{
  "name": "Financial document extraction from Gmail to Google Sheets",
  "nodes": [
    {
      "id": "dabf59bf-864c-47e2-8289-69fba6c42bd0",
      "name": "Look for Invoices",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -768,
        368
      ]
    },
    {
      "id": "bf4111ad-870d-4a37-82ac-343828f3c7b9",
      "name": "Get Email Content",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -544,
        368
      ]
    },
    {
      "id": "b5bcf67f-528a-493a-947a-c3070ebf8b66",
      "name": "Guardrail: Is Finance?",
      "type": "@n8n/n8n-nodes-langchain.guardrails",
      "position": [
        -336,
        368
      ]
    },
    {
      "id": "4f653917-7633-4e1b-b3ad-726ae5824cd9",
      "name": "Configuration: User Settings",
      "type": "n8n-nodes-base.set",
      "position": [
        0,
        0
      ]
    },
    {
      "id": "fdf114cb-d6f1-421d-8a54-bbbdd6a9154b",
      "name": "IF (Guardrail Passed)",
      "type": "n8n-nodes-base.if",
      "position": [
        208,
        336
      ]
    },
    {
      "id": "75c2ee44-d59d-4029-804e-14b8a365dfb2",
      "name": "Filter Finance Keywords",
      "type": "n8n-nodes-base.filter",
      "position": [
        592,
        432
      ]
    },
    {
      "id": "92f7d2c2-9adb-4eb0-8aa0-66e1e4cfb36a",
      "name": "Check for Attachment",
      "type": "n8n-nodes-base.if",
      "position": [
        -576,
        1040
      ]
    },
    {
      "id": "6a74d0c3-ba12-4c9a-9db2-fa2b52f12e96",
      "name": "Extract PDF Data",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        -240,
        816
      ]
    },
    {
      "id": "a09fb13e-14e1-4a55-b4af-1aba901ae6bf",
      "name": "AI Agent (PDF OCR)",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -32,
        800
      ]
    },
    {
      "id": "2a0195e7-aa9d-460f-8a91-9752b80a3005",
      "name": "AI Agent (Email OCR)",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -32,
        1088
      ]
    },
    {
      "id": "59761143-4f1a-42a4-b3e7-acad993d9858",
      "name": "Validate Extraction",
      "type": "n8n-nodes-base.code",
      "position": [
        528,
        992
      ]
    },
    {
      "id": "c298c89e-3bf2-496c-a5eb-1cf0c5c4265a",
      "name": "Check for Errors",
      "type": "n8n-nodes-base.if",
      "position": [
        800,
        992
      ]
    },
    {
      "id": "befb7153-1a70-4265-8472-0fa9acca2620",
      "name": "Apply Finance Rules",
      "type": "n8n-nodes-base.code",
      "position": [
        1040,
        672
      ]
    },
    {
      "id": "9ad1658b-9257-45a7-b049-ef6bfdcc38d7",
      "name": "Log to Invoices Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1376,
        672
      ]
    },
    {
      "id": "9d54059e-7fc6-4954-bbc5-7f6b492a8f67",
      "name": "Send Confirmation Email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1632,
        672
      ]
    },
    {
      "id": "78f48238-71b3-49e9-a492-b23f6600dcdd",
      "name": "Log Error to Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1088,
        1248
      ]
    },
    {
      "id": "bde3beda-0e4f-4d62-ba00-ab44f9d92aff",
      "name": "Send Error Notification",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1424,
        1248
      ]
    },
    {
      "id": "7d9dd7c1-9d9a-450f-bca3-ae146cfc44f0",
      "name": "Sticky Note Guardrail",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -368,
        240
      ],
      "parameters": {
        "width": 288,
        "height": 288,
        "content": "## 1. Finance Guardrails\nUses Gemini/LangChain to detect if the email is actually a financial document."
      }
    },
    {
      "id": "339c869a-f63b-438f-9d56-fcc79b62cf6d",
      "name": "Sticky Note Extraction",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -272,
        656
      ],
      "parameters": {
        "width": 480,
        "height": 608,
        "content": "## 2. Dual Extraction Path\nIf Attachment -> **PDF OCR Agent**\nIf No Attachment -> **Email Body Agent**\n\nBoth normalize data into the same JSON structure."
      }
    },
    {
      "id": "b9ac3d47-1b42-4679-a4d8-d4566cdba90a",
      "name": "Sticky Note Logic",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        912,
        544
      ],
      "parameters": {
        "width": 352,
        "height": 320,
        "content": "## 3. Business Logic\n- **GL Coding**: Auto-categorizes vendors (Uber -> Travel).\n- **Thresholds**: Flags high amounts (> $1000) for approval."
      }
    },
    {
      "id": "c4c483cb-489d-44dd-955b-2b9f852b40d3",
      "name": "gpt 4o mini",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -32,
        960
      ]
    },
    {
      "id": "465751b4-3b8c-4a9c-b393-41ff173d79c0",
      "name": "Gemini 2.5 flash",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -336,
        480
      ]
    },
    {
      "id": "69b67a16-43f8-402f-a764-3b222e2e083f",
      "name": "Log Success Metrics",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1904,
        672
      ]
    },
    {
      "id": "cc699a3b-f602-4f56-ad0a-60d2cc66f96d",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1344,
        176
      ],
      "parameters": {
        "width": 512,
        "height": 1216,
        "content": "## Overview\n### **[Gtaras](https://n8n.io/creators/tarasidis/)**  \n\nManual financial reconciliation is tedious and prone to error. This workflow functions as an AI Financial Controller, automatically "
      }
    },
    {
      "id": "199af4d5-b569-4220-9748-be6ebd1d9afd",
      "name": "Sticky Note21",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1024,
        1152
      ],
      "parameters": {
        "width": 640,
        "height": 304,
        "content": "## ⚠️ Error Handling Flow\n### Any failures are logged and admins are notified"
      }
    },
    {
      "id": "c2cf3003-6430-4970-812e-b96ba5d98f10",
      "name": "Sticky Note17",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1792,
        608
      ],
      "parameters": {
        "width": 352,
        "height": 248,
        "content": "## 📊 Success Metrics Logger"
      }
    }
  ],
  "connections": {
    "gpt 4o mini": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent (PDF OCR)",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "AI Agent (Email OCR)",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Check for Errors": {
      "main": [
        [
          {
            "node": "Apply Finance Rules",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log Error to Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract PDF Data": {
      "main": [
        [
          {
            "node": "AI Agent (PDF OCR)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini 2.5 flash": {
      "ai_languageModel": [
        [
          {
            "node": "Guardrail: Is Finance?",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Get Email Content": {
      "main": [
        [
          {
            "node": "Guardrail: Is Finance?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Look for Invoices": {
      "main": [
        [
          {
            "node": "Get Email Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent (PDF OCR)": {
      "main": [
        [
          {
            "node": "Validate Extraction",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Error to Sheet": {
      "main": [
        [
          {
            "node": "Send Error Notification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Apply Finance Rules": {
      "main": [
        [
          {
            "node": "Log to Invoices Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate Extraction": {
      "main": [
        [
          {
            "node": "Check for Errors",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent (Email OCR)": {
      "main": [
        [
          {
            "node": "Validate Extraction",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check for Attachment": {
      "main": [
        [
          {
            "node": "Extract PDF Data",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "AI Agent (Email OCR)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF (Guardrail Passed)": {
      "main": [
        [
          {
            "node": "Filter Finance Keywords",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log to Invoices Sheet": {
      "main": [
        [
          {
            "node": "Send Confirmation Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Guardrail: Is Finance?": {
      "main": [
        [
          {
            "node": "Configuration: User Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Finance Keywords": {
      "main": [
        [
          {
            "node": "Check for Attachment",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Confirmation Email": {
      "main": [
        [
          {
            "node": "Log Success Metrics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Configuration: User Settings": {
      "main": [
        [
          {
            "node": "IF (Guardrail Passed)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}