🧾 Extract and validate invoice data with Google Gemini and Google Sheets

⚡ 30 views · 🧾 Invoice Processing

Description

Quick overview

This workflow accepts an invoice file via an n8n chat trigger, uses Google Gemini to extract structured invoice data, validates it against an existing Google Sheets log, appends valid line items to the sheet, and sends a formatted confirmation or failure alert via Gmail.

How it works

  1. Receives a chat message with an uploaded invoice document.
  2. Uses Google Gemini to extract the vendor, invoice number, date, total amount, and all line items as a clean JSON object.
  3. Converts the extracted JSON into per-line-item records, builds an HTML invoice summary for email, and loads existing rows from Google Sheets for comparison.
  4. Validates each item by checking for missing critical fields and whether the invoice number already exists in Google Sheets.
  5. If validation passes, appends each line item as a new row in Google Sheets and then prepares a summary of the inserted data.
  6. Sends a Gmail message with the formatted HTML invoice breakdown when processing succeeds, or sends a Gmail alert email explaining the validation failure.

Setup

  1. Add Google Gemini (PaLM) API credentials and ensure the chat trigger allows file uploads so the invoice is available as binary input.
  2. Connect Google Sheets OAuth credentials and update the target spreadsheet and sheet tab to match your invoice log and column headers.
  3. Connect Gmail OAuth2 credentials and update the recipient email address and subject/message templates as needed.

Requirements

Customization

Additional info

Prompt Tuning: The accuracy of the data extraction depends on the quality of the invoice file. If you are using handwritten or poorly scanned invoices, you may want to update the Gemini node prompt to enforce stricter parsing rules.

Testing Tip: Before activating the production workflow, test it with 2-3 sample invoices using the Chat interface to ensure that the column names in your Google Sheets perfectly match the data keys generated by the Gemini node.

Error Handling: If an invoice fails validation (e.g., duplicate invoice number or missing totals), the workflow will automatically skip the Google Sheets step and immediately trigger the Gmail alert node, saving you from cluttered data logs.

🔗 Nodes Used

Google Sheets, Gmail, Summarize, Chat Trigger, Google Gemini

📥 Import

Download workflow.json and import into n8n: Workflow menu → Import from File

📖 Importing guide · 🔑 Credential setup