AI Financial Controller for Invoice Extraction & Categorization - n8n Workflow

Use this advanced n8n workflow template to automate financial operations. It utilizes AI Guardrails and OCR extraction from Gmail emails and attachments, applying GL coding and logging structured data into Google Sheets.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Finance Teams: For automating accounts payable intake and reducing manual data entry for invoices.
Operations Managers: Seeking high-volume automation for expense tracking and real-time budget monitoring.
n8n Automation Specialists: Looking for complex n8n templates demonstrating AI guardrails, dual OCR paths, and robust error handling within a single n8n workflow.
Users needing robust intake pipelines: Anyone who needs a reliable n8n trigger to start a sequence of data extraction and validation.

Overview

Manual financial reconciliation is notoriously tedious and prone to human error. This comprehensive n8n workflow transforms your inbox into an intelligent, self-managing accounts payable intake system. This specific n8n workflow utilizes powerful AI models (Gemini for filtering and GPT-4o for OCR) to handle complex documents.

The key innovation of this n8n template is the use of an AI 'Guardrail' that filters out irrelevant emails (like newsletters or marketing content) before the expensive extraction process begins, saving API costs and ensuring data quality. After extraction, the workflow applies custom business rules—such as General Ledger (GL) coding based on vendor name and setting mandatory approval statuses based on the transaction amount—making it an indispensable automation tool.

How it Works

The process begins with the Look for Invoices n8n trigger, a Gmail Trigger node configured to poll the INBOX for new emails.


  1. Ingestion & Guardrail: The Get Email Content n8n node fetches the message body and attachments. The Guardrail: Is Finance? node (using Gemini 2.5 flash) acts as a strict filter, checking if the email text contains explicit evidence of an invoice or financial transaction. If this specialized n8n node fails, the workflow terminates.

  2. Configuration & Filtering: Valid emails proceed through the Configuration: User Settings node, which loads critical variables (Sheet ID, Admin Email). The Filter Finance Keywords node further confirms the transaction by checking the subject line for terms like 'Invoice', 'Receipt', or 'Payment'.

  3. Dual AI Extraction: The Check for Attachment n8n node splits the flow. If a PDF attachment exists, the Extract PDF Data n8n node performs OCR preparation, and the AI Agent (PDF OCR) (using GPT-4o mini) extracts the structured invoice details. If no attachment is found, the AI Agent (Email OCR) extracts the necessary data directly from the email body.

  4. Validation & Logic: The Validate Extraction code n8n node ensures the AI output is correctly formatted JSON and checks for crucial missing fields (Vendor Name, Total Amount). If valid, the Apply Finance Rules n8n node executes custom business logic to assign GL categories and determine the approval_status based on thresholds (e.g., > $5,000 requires VP Approval).

  5. Logging and Notification: The final processed data is logged into the Invoices tab via the Log to Invoices Sheet n8n node. A confirmation email is sent via Gmail, and execution metrics are logged to the Success Metrics sheet. If any validation or parsing error occurs, the dedicated error path (Log Error to Sheet and Send Error Notification) ensures the admin is immediately alerted.

Installation Guide

To set up this powerful n8n workflow, follow these steps:


  1. Google Sheets Setup: Copy the provided Google Sheet template (link provided in the sticky note within the workflow). This sheet must contain the 'Invoices', 'Error Logs', and 'Success Metrics' tabs.

  2. Import Workflow: Import this n8n workflow JSON into your n8n instance.

  3. Credential Setup: Ensure you have configured the following n8n credentials:

Gmail: For the n8n trigger and sending notifications.
Google Sheets: To interact with the logging spreadsheet.
OpenAI: Required for the high-accuracy OCR Agents (GPT-4o).
Google Gemini (or PaLM/LLM): Required for the Guardrail: Is Finance? n8n node.

  1. Configure User Settings: Open the Configuration: User Settings n8n node and update the expressions:

gSheetID: Paste the ID from the URL of your newly copied Google Sheet.
adminEmailForErrors: Enter the email address that should receive success confirmations and critical error alerts.

Node Details

This n8n workflow utilizes several specialized n8n nodes:

Gmail Trigger (Look for Invoices): The starting n8n trigger for the workflow. It polls the inbox, typically hourly, looking for new mail.
Guardrails n8n Node (Guardrail: Is Finance?): Uses a large language model (LLM) credential (Gemini 2.5 flash in this configuration) with a defined topicalAlignment prompt. Its function is to determine if the email text is financially relevant before proceeding, effectively blocking noise.
Extract From File n8n Node (Extract PDF Data): This n8n node specifically prepares PDF attachments found in the email for AI processing by converting the binary PDF into readable text.
AI Agent n8n Node (AI Agent (PDF OCR) & AI Agent (Email OCR)): These n8n nodes use an OpenAI LLM (configured for GPT-4o mini) with a strict system message to perform JSON-structured extraction (OCR). This ensures standardized data output regardless of whether the source was a PDF or the email body.
Code n8n Node (Validate Extraction): A critical n8n node for data integrity. It validates the AI-generated output, ensuring it's valid JSON and checking for the presence of required fields like totalamount and vendorname.
Code n8n Node (Apply Finance Rules): This n8n node contains proprietary business logic, dynamically assigning GL categories (e.g., '6000 - Software & Hosting') and defining approval statuses based on custom amount thresholds.


  • Google Sheets n8n Node (Log to Invoices Sheet & Log Error to Sheet): Used for persistence, logging the final, cleaned data to the main ledger and dedicated error logs, respectively. The Google Sheets n8n node uses an expression to reference the Document ID set in the configuration node.

Related n8n Workflows

Free

Nodes: 13 Nodes
Updated: December 26 2025
View all
Created by
Gtaras
Gtaras

If you want to discuss integration with other systems (like ServiceNow!), please reach out to our dedicated support email: [email protected]

Featured*