Extract, validate, and log email invoices from Gmail to Google Sheets with GPT-4
Needs changesNeeds changes. This template uses 1 thing(s) that n8n 3.0 removes: AI Agent v1 (old agent modes). 1 breaking item(s) found. Static check, last run 2026-10-19.
What to replace before upgrading
| Removed in 3.0 | Replace with |
|---|---|
| AI Agent v1 (old agent modes) AI Agent (Email OCR) (v1.9) | Latest AI Agent node (Tools Agent). For SQL Agent, use a Postgres or MySQL tool with a recent AI Agent. |
Nodes used (9)
- Gmail
n8n-nodes-base.gmail - Guardrails
@n8n/n8n-nodes-langchain.guardrails - If
n8n-nodes-base.if - Filter
n8n-nodes-base.filter - AI Agent
@n8n/n8n-nodes-langchain.agent - Code
n8n-nodes-base.code - Google Sheets
n8n-nodes-base.googleSheets - OpenAI Chat Model
@n8n/n8n-nodes-langchain.lmChatOpenAi - n8n Form Trigger
n8n-nodes-base.formTrigger
What it does
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 invoice/receipt fields via an OCR-style agent, validates and auto-categorizes each expense, generates a unique case ID, and appends the result to a Google Sheet for accounting or downstream automations. --- Key Features - Trigger: Form submission or scheduled fetch (sample On form submission node included) - AI Filter: Guardrail node determines whether an email is finance-related (payments, invoices, receipts) - Keyword Filter: Filters common invoice/bill/payment subject keywords - Extraction: Language-model agent returns normalized JSON: - vendorname - invoicedate (YYYY-MM-DD) - invoiceid - totalamount - taxamount - currency - itemssummary - vendortaxid - Validation: Code node checks required fields and amount formats; flags extraction errors - Categorization: Rule-based expense categorizer (software & hosting, subscriptions, travel, payroll, etc.) with MCC/vendor fallbacks - Output: Appends structured rows to a Google Sheet with mapped columns: - invoiceid, vendorname, invoicedate, totalamount, currency, taxamount, glcategory, approvalstatus, timestamp, caseid, itemssummary, vendortaxid, processedat - High Accuracy: Low false-positive rate using combined AI guardrails + subject filtering - Quick Setup: Example nodes and credentials pre-configured in the template --- Included Nodes & Flow Highlights On form submission (date picker trigger) → Get Email Content (Gmail) → Guardrail: Is Finance? (LangChain Guardrails) → IF (Guardrail Passed) → Filter Finance Keywords → AI Agent (Email OCR) → Validate Extraction → Check for Errors → Apply Finance Rules → Log to Invoices Sheet (Google Sheets) (Full node list and configuration included in the template.) --- Requirements & Credentials - Gmail OAuth2 (read access) — for fetching emails - OpenAI API key (or compatible LLM) — for guardrails & extraction - Google Sheets OAuth2 — to append rows to the invoice sheet Recommended: Use the Google Sheet ID included in the template, or replace it with your own Sheet ID and gid. --- Quick Setup Guide 👉 Demo & Setup Video 1. Import the template into n8n 2. Connect and authorize credentials: Gmail, Google Sheets, OpenAI (or preferred LLM) 3. Update the Google Sheet ID / sheet gid if using your own sheet 4. (Optional) Adjust the Guardrail topicalAlignment threshold or filter keywords 5. Test using the form trigger or a single email, then enable the workflow --- Configuration Tips - The extraction agent outputs a strict JSON schema — keep it for reliable downstream mapping - Use a low LLM temperature (0.2) for deterministic extraction - For non-USD currencies, ensure your accounting system supports the currency field or add a conversion step - For high-volume inboxes, enable batching or rate-limit the Gmail node to avoid API quota issues --- Privacy & Security - This template processes real email content and financial data — store credentials securely - Restrict access to the n8n instance to authorized users only - Review data-retention policies if using a hosted LLM service --- Example Use Cases - Auto-log vendor invoices from email into an accounting Google Sheet - Build an audit trail with case IDs for finance teams - Preprocess incoming receipts before forwarding to AP tools or ERPs --- Tags (Recommended) finance, invoices, email, ai, ocr, google-sheets, automation, accounting, n8n-template