Net + VAT Must Equal Gross: An n8n Workflow Checks Invoice Math in Code Before Writing to Sheets
- Level Intermediate
- Setup1–3 hrs (estimated)
- Evidence Some evidence
- CostNot stated in source
- No-codeYes
What they did
AI can read an invoice and still get the sums wrong. This free n8n template watches one Gmail label for supplier invoices, pulls the PDF text, and has OpenAI fill a strict set of fields. Then plain code checks the math: net plus VAT must equal gross, line items must add up, and the VAT rate must be allowed. Rows that pass go to an Invoices tab; failures go to an Exceptions tab with the reason.
How it went
Invoices logged automatically, with bad math caught before it reaches your books.
Worth knowing
- Shared on the n8n forum by someone who builds n8n workflows for small UK businesses; the template is free. Credit notes look like invoices with a negative sign.
Prompt
Cleaned version rewritten from the source — not a direct quote.
Build a workflow: watch Gmail label [label] for supplier invoices with PDF attachments. Extract the text and have the AI return supplier, invoice number, dates, currency, net, VAT, gross and line items, leaving any field empty if not found. Then check in code: required fields present, net + VAT = gross (allow rounding), line items sum to net, VAT rate in [allowed rates], negative totals flagged. Write passing rows to an Invoices sheet and failures to an Exceptions sheet with the reason.
Recommended
Try it in Grok Bot
Grok Bot can read invoice PDFs from your inbox and double-check the math the same way.
- Copy the prompt (button below).
- Open Grok Bot chat and paste it. Replace any [bracketed] placeholders.
- Connect the listed tools (Gmail, Google Sheets) as connectors when Grok Bot asks.
- If the task repeats, ask: "Make this a daily routine."
Alternatives: the same prompt works in n8n, Claude, ChatGPT Agent, OpenClaw.
Set it up
Tools: Gmail, Google Sheets · Stack: n8n + Gmail + OpenAI + Google Sheets
- Read the original source for full context.
- Connect the tools your agent needs.
- Paste the prompt and replace [bracketed] placeholders.
- Run once manually and check the output before scheduling it.
Generic suggested steps, not from the source.
Evidence
n8n community post with a free library template: Gmail label, strict schema, code-side math checks, Invoices/Exceptions tabs. Author builds workflows for UK businesses; template free
Source: Web · 2026-10-19 · Verified by us: not yet · Report broken or outdated