See llms.txt for all machine-readable content.

Back to Templates

Extract invoice data to Google Sheets with Ollama and Gmail alerts

Quick overview

This workflow lets you upload an invoice (PDF or image), extracts structured invoice data using local Ollama models, validates totals and line items, appends the results to Google Sheets, and sends a Gmail alert when the extracted data needs review.

How it works

  1. Receives an invoice upload (PDF, PNG, or JPG) through an n8n Form.
  2. Routes the file by MIME type, extracting text from PDFs and converting images to a Base64 payload.
  3. Sends the PDF text or image to Ollama (/api/chat) using Qwen models to extract vendor, invoice details, totals, and line items as structured JSON.
  4. Parses and repairs the AI output by normalizing numeric fields, filling missing tax/currency/invoice number from PDF text when available, and attempting to recover missed line items.
  5. Validates required fields and checks calculations (quantity × unit price, line items vs subtotal, and subtotal + tax vs total) to mark the invoice as OK or Needs review.
  6. Appends the extracted invoice record (including status and notes) to a Google Sheets spreadsheet.
  7. Sends a Gmail email alert with the issues when the invoice is marked Needs review.

Setup

  1. Install and run Ollama and pull the required models (qwen2.5:3b and qwen2.5vl:3b), then ensure n8n can reach Ollama at the configured URL (update to host.docker.internal if running n8n in Docker).
  2. Create a Google Sheet with columns matching the workflow output (processed_at, vendor_name, invoice_number, invoice_date, currency, subtotal, tax, total, line_items, status, notes) and add Google Sheets OAuth credentials.
  3. Set your Google Sheets document ID (replace YOUR_SHEET_ID) and target sheet/tab in the Google Sheets append step.
  4. Add Gmail OAuth credentials and replace the recipient address ([email protected]) used for review alerts.