{
  "name": "Extract, validate, and log email invoices from Gmail to Google Sheets with GPT-4",
  "nodes": [
    {
      "id": "3ba62e63-5a3d-4cbc-a110-833bb0199d98",
      "name": "Get Email Content",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -1472,
        176
      ]
    },
    {
      "id": "44797303-c942-44ac-a083-a02d1ed6b360",
      "name": "Guardrail: Is Finance?",
      "type": "@n8n/n8n-nodes-langchain.guardrails",
      "position": [
        -1152,
        176
      ]
    },
    {
      "id": "143a677b-1c72-4b0f-b5bc-bab4c0c3cd72",
      "name": "IF (Guardrail Passed)",
      "type": "n8n-nodes-base.if",
      "position": [
        -800,
        176
      ]
    },
    {
      "id": "6b7923e4-1b33-4154-8ce5-a93835dfa616",
      "name": "Filter Finance Keywords",
      "type": "n8n-nodes-base.filter",
      "position": [
        -576,
        176
      ]
    },
    {
      "id": "9ae08dc6-847e-417f-b7f6-2f62675799ce",
      "name": "AI Agent (Email OCR)",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -240,
        176
      ]
    },
    {
      "id": "81c5e6d4-a43b-442c-b6f7-f24502830cdc",
      "name": "Validate Extraction",
      "type": "n8n-nodes-base.code",
      "position": [
        112,
        176
      ]
    },
    {
      "id": "dc6ce290-b2d6-4ae9-9c34-1cb962b385a2",
      "name": "Check for Errors",
      "type": "n8n-nodes-base.if",
      "position": [
        336,
        176
      ]
    },
    {
      "id": "4b8ddd2d-2fcd-47c1-aa13-95c1b6c09394",
      "name": "Apply Finance Rules",
      "type": "n8n-nodes-base.code",
      "position": [
        560,
        176
      ]
    },
    {
      "id": "22378f77-6fee-40d6-a3f6-c185855106b3",
      "name": "Log to Invoices Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        784,
        176
      ]
    },
    {
      "id": "c09451c0-a59f-4d60-bd6a-91308d937a33",
      "name": "gpt 4o mini",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -240,
        336
      ]
    },
    {
      "id": "c3d58a12-9d19-4c92-a9d5-845e6b254a38",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1776,
        -48
      ],
      "parameters": {
        "width": 512,
        "height": 544,
        "content": "# Get all emails\n## Connect Gmail and fetch incoming messages or selected folders; batch or trigger-based retrieval ensures full inbox coverage for automatic processing."
      }
    },
    {
      "id": "912cd585-df40-42fc-a1f6-5ee0d4fd6c51",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -1136,
        336
      ]
    },
    {
      "id": "6acc74c6-538f-40de-a356-226cde040aee",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2544,
        -48
      ],
      "parameters": {
        "width": 688,
        "height": 544,
        "content": "Inbox2Ledger is an end-to-end **n8n template** that turns a noisy finance inbox into a clean, structured ledger. It fetches emails, uses AI guardrails to keep only finance-relevant messages, extracts "
      }
    },
    {
      "id": "ad53c100-afae-4642-80d3-a54a7fc6f15b",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1216,
        -48
      ],
      "parameters": {
        "width": 848,
        "height": 544,
        "content": "# Filter finance emails\n## Apply AI guardrails and keyword filters to isolate invoices, receipts, and payments; reduce false positives and route only finance messages."
      }
    },
    {
      "id": "fd07a032-91ce-44c4-9bb3-dc59595368bf",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -320,
        -48
      ],
      "parameters": {
        "width": 1360,
        "height": 544,
        "content": "# Extract details and log\n## Use LLM/OCR agent to extract vendor, date, invoice_id, amounts; validate entries, categorize expenses, and append structured rows to Google Sheets."
      }
    },
    {
      "id": "15ad6c48-520c-41e0-9ad0-1c9da8bce60f",
      "name": "Enter Date till which you want email to be fetched",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -1680,
        176
      ]
    }
  ],
  "connections": {
    "gpt 4o mini": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent (Email OCR)",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Check for Errors": {
      "main": [
        [
          {
            "node": "Apply Finance Rules",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Email Content": {
      "main": [
        [
          {
            "node": "Guardrail: Is Finance?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Guardrail: Is Finance?",
            "type": "ai_languageModel",
            "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
          }
        ]
      ]
    },
    "IF (Guardrail Passed)": {
      "main": [
        [
          {
            "node": "Filter Finance Keywords",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Guardrail: Is Finance?": {
      "main": [
        [
          {
            "node": "IF (Guardrail Passed)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Finance Keywords": {
      "main": [
        [
          {
            "node": "AI Agent (Email OCR)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enter Date till which you want email to be fetched": {
      "main": [
        [
          {
            "node": "Get Email Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}