AI-Powered Invoice Extraction, Validation, and Tracking System - n8n Workflow

Automate invoice processing using this advanced n8n workflow. Extract data from images or PDFs with Gemini AI, validate required fields, prevent duplicate entries in Google Sheets, and send instant Gmail notifications using a comprehensive n8n node setup.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Accounting Departments: Users seeking to eliminate manual data entry errors from physical invoices.

  • Small Business Owners: Individuals needing a reliable, automated system for expense tracking.

  • n8n Automation Engineers: Developers looking for complex, real-world n8n templates integrating vision AI and core database operations.

  • Finance Teams: Groups requiring automated duplicate checks and detailed reporting in Google Sheets.

Overview

Manual invoice processing is time-consuming and prone to human error. This comprehensive n8n workflow provides an end-to-end solution. It starts by securely receiving an invoice file (image or PDF), utilizes Google Gemini’s vision capabilities to extract unstructured data, and then uses a dedicated AI agent within the n8n node ecosystem to transform that raw data into a strict JSON schema. The system automatically checks Google Sheets for duplicate entries based on the invoice ID, validates that all mandatory fields (like total amount and date) are present, and finally logs the clean data. This specialized n8n automation ensures data accuracy, reduces operational overhead, and provides immediate feedback via Gmail notifications for success, duplication, or missing field errors. This powerful n8n workflow demonstrates the potential of AI integration in standard business operations.

How it Works

The entire process is initiated by an n8n trigger and involves several crucial steps:


  1. Trigger & File Upload: The n8n workflow starts when a new chat message containing an attached invoice (image or PDF) is received. Simultaneously, the original invoice file is uploaded and saved to Google Drive using a dedicated n8n node.

  2. AI Extraction: The file is passed to the Analyze image1 n8n node, which uses the Google Gemini 1.5-Flash model to perform OCR and vision analysis, extracting raw text information about the invoice details.

  3. Data Structuring: The raw text is fed into the AI Agent1 n8n node. This agent enforces a strict JSON output structure (defining fields like invoiceid, shopname, Total, and item lists) using a system message prompt, making the data highly reliable.

  4. Deduplication Check: The structured payload is used by the Get data Google Sheets n8n node to search the spreadsheet for an existing entry matching the extracted invoice_id.

  5. Conditional Routing: An n8n If node (check if Data exist or not in table) checks the result. If a duplicate is found, the n8n workflow sends a 'Duplicate entry' alert via Gmail. If it is new, it proceeds.

  6. Mandatory Field Validation: The Check Mandatory fields n8n node executes custom code to ensure key fields (ID, total, date) are not empty. If the data fails validation, the workflow routes to a different branch and uses a Gmail n8n node to send a 'Missing field error' notification.

  7. Sheet Append: If the data is complete and unique, the Append data to sheet Google Sheets n8n node adds the full, structured record to the designated expense tracker sheet.

  8. Confirmation: Finally, the Send successful email Gmail n8n node sends a detailed HTML confirmation to the user, confirming the successful record of the new invoice.

Installation Guide

To deploy this powerful n8n workflow, follow these steps:


  1. Import: Copy the provided JSON into your self-hosted or cloud n8n instance using the 'Import from JSON' function.

  2. Credentials Setup: This n8n template requires three main credentials:

Google Gemini (PaLM) API: Used for the vision and chat models.
Google Sheets OAuth2 API: Requires access to the target Google Sheet document.
* Gmail OAuth2: Used for sending success, duplicate, and error notifications. Ensure the sendTo email addresses in the Gmail n8n nodes are updated.

  1. Google Sheets Configuration: Configure the Get data and Append data to sheet n8n node parameters with the correct Spreadsheet ID and Sheet Name corresponding to your expense tracker.

  2. Webhook Activation: Ensure the starting When chat message received n8n trigger is active. Note its webhook URL and ensure your chat platform (if integrated outside of the native n8n chat node) is configured to send messages to it.

  3. Customization: Review the validation logic in the Check Mandatory fields n8n node to adjust the required fields if necessary.

Node Details


  • When chat message received (n8n trigger): The starting point for this n8n workflow. It is configured to listen for new chat messages and handle file uploads (images/PDFs) containing the invoice.

  • Upload invoice to drive (Google Drive n8n node): Stores the original binary invoice file for archival purposes immediately after the n8n trigger fires.

  • Analyze image1 (Google Gemini n8n node): Uses the models/gemini-1.5-flash model and the analyze operation to convert the binary invoice image into raw, descriptive text data.

  • AI Agent1 (n8n node): Takes the raw text and applies a complex system message constraint to output the data strictly in the predefined invoice JSON structure, ensuring standardized data for the downstream n8n nodes.

  • Get data (Google Sheets n8n node): Performs a lookup operation in the configured spreadsheet, searching for the extracted invoiceid in the EntryID column to facilitate the duplicate check.

  • check if Data exist or not in table (n8n If node): A core flow control n8n node that branches the workflow based on whether the Get data node returned any items, determining if the invoice is new or a duplicate.

  • Check Mandatory fields (n8n Code node): Custom scripting checks for the presence of essential fields (invoice_id, Total, date) before allowing data insertion. This increases the reliability of the n8n workflow.

  • Append data to sheet (Google Sheets n8n node): The final action n8n node that inserts the clean, validated invoice data as a new row in the designated Google Sheet.

  • Send successful email (Gmail n8n node): Sends an HTML-formatted confirmation email detailing the extracted invoice data after successful entry into the sheet.

Related n8n Workflows

Free

Nodes: 11 Nodes
Updated: December 26 2025
View all
Created by

an AI automation enthusiast.

Featured*