N8N · AI AUTOMATION
n8n invoice capture: an AI workflow that reads every invoice in the inbox
Twenty-two nodes, four stages and no manual data entry. A walkthrough of the capture workflow that treats every incoming document as untrusted input.
A node-by-node walkthrough of the invoice and receipt capture workflow, narrated over the n8n canvas.
In short
The workflow watches a Gmail inbox, splits every email into its attachments, keeps only readable files inside a size cap, sends each one to Claude for extraction, validates the result against a strict schema, searches the ledger for the same vendor and invoice number, then writes one row per file and labels the email. Finance is only asked to look at the documents the checks could not clear.
- Platform
- n8n
- Nodes
- 22
- Stages
- 4
- Manual data entry
- None
- AI step
- Claude, extraction only
- Walkthrough
- 1 min 8 sec
THE SHORT VERSION
What this
walkthrough shows.
- Filtering happens before the AI step, so unreadable files and already-captured files never reach the model.
- The document is treated as untrusted data, because a stranger sent it.
- A schema guard checks the shape of what comes back: plain numbers, ISO dates, allowed currencies, and subtotal plus tax equal to the total.
- A duplicate check on vendor and invoice number runs before any ledger row is written.
- Nothing is dropped silently — unreadable attachments raise an alert to finance.
The four stages
- 1Capture, filter & de-duplicate
A Gmail trigger watches the inbox, each email is split into attachment files, unreadable formats are labelled and flagged, files already in the ledger are skipped, and a daily cap keeps AI spend predictable.
- 2Claude extraction + schema guard
Files loop through the model one at a time, inside the daily cap. Claude reads the invoice or receipt, and a validation step checks the structure of the response before anything downstream trusts it.
- 3Duplicate guard & ledger
The workflow searches the ledger for the same vendor and invoice number, decides whether the document is recorded, needs review or is a duplicate, and adds a row to the expense ledger.
- 4Review routing & labels
Doubtful items are labelled Needs Review and finance is alerted. Everything handled is labelled Processed, so the same email is never read a second time.
What the workflow actually does
Invoices and receipts rarely arrive in one tidy format. They turn up as PDF attachments, as photos taken on a phone, forwarded in threads, or pasted into a Word document by a supplier who means well. Somebody then opens each one, reads the vendor, the invoice number, the date, the currency and the total, and types all of it into a spreadsheet or an accounting tool.
This workflow removes the typing, but it is deliberately not a single AI step. Twenty-two nodes are arranged into four stages, and most of them exist to decide what the AI should never see and what a person still has to look at.
The walkthrough above moves through the canvas stage by stage. What follows is the same structure in writing, including the reasoning behind each guard.
Stage 1 — Capture, filter and de-duplicate
A Gmail trigger watches a dedicated inbox for invoices and receipts. Each email is split into its attachment files, so an email carrying four receipts becomes four items to process rather than one blob of text.
Only PDFs and images inside the size caps go through. That single condition does a lot of work: it keeps signature images and marketing banners out of the pipeline, and it keeps file sizes predictable for the model call that follows.
- Unreadable files are flagged, not droppedA HEIC photo or a Word document cannot be read reliably, so the email is labelled and finance is told. Nothing vanishes silently — that is the difference between a workflow people trust and one they quietly stop relying on.
- Files already in the ledger are skippedRe-sent and forwarded documents are common. Checking the ledger before the model call means a duplicate costs nothing.
- A daily cap keeps AI spend predictableThe cap bounds the number of documents sent to the model each day, so an unexpected flood of attachments cannot turn into an unexpected bill.
Stage 2 — Claude reads the document as untrusted input
The extraction step itself is short. Files loop through one at a time, a condition checks that the run is still within the daily cap, and Claude reads the invoice or receipt.
The important design decision is how the document is treated. An invoice arrives from outside the business. It is a file a stranger sent, and its contents are data to be read, never instructions to be followed. Treating attachments as untrusted input is the same discipline you would apply to any other user-supplied content, and it matters more once a model is in the path.
What comes back is then checked by a schema guard before anything downstream is allowed to use it.
- Plain numbersAmounts come back as numbers, not as strings with currency symbols, thousands separators or trailing notes.
- ISO datesOne date format, so 03/04 is never ambiguous between March and April.
- Allowed currenciesA fixed list the business actually transacts in, rather than whatever three letters appeared on the page.
- Arithmetic that agreesSubtotal plus tax has to equal the total. It is a simple test, and it catches a surprising share of misreads on a crowded or low-quality document.
Stage 3 — The duplicate guard and the ledger
Before any row is written, the workflow looks for the same vendor and invoice number already recorded. This is the check that protects the money. Duplicate payments usually come from an ordinary sequence of events: a supplier re-sends a statement, somebody forwards the thread to accounts, and the document is processed twice by two different people on two different days.
Every file then gets exactly one ledger row, with a status attached: recorded, needs review, or duplicate. One row per file keeps the ledger honest. There is no state where a document was processed but left no trace.
Stage 4 — Review routing and labels
The last stage decides what a person sees. Anything the checks could not clear is labelled Needs Review and finance is alerted, so a human looks at exceptions rather than at the whole inbox.
Everything handled is labelled Processed. The labels are not decoration — they are the workflow's memory inside the mailbox. If a run is repeated, or the workflow is restarted after a change, the label is what stops the same email being read twice.
Why the guards matter more than the extraction
Reading a total off an invoice is the part of this problem a current model handles well. It is also the part that carries the least risk, because a misread number that fails the arithmetic check never reaches the ledger.
The risk sits around the extraction: a document processed twice, an unreadable file silently skipped, a currency assumed, a model bill that grows without anyone noticing, or output trusted because it looked well-formed. Of the twenty-two nodes in this workflow, the ones doing filtering, validation, duplicate checking, capping and labelling outnumber the ones doing the reading.
That ratio is the point. An automation that handles finance documents earns its place by being predictable on the bad days, not by being impressive on the good ones.
What it takes to run this on your own inbox
The structure transfers to most businesses that receive documents by email. The parts that need defining are specific to you:
- A dedicated inboxA single address that suppliers send to, so the trigger has a clean scope.
- A ledger with a stable keyVendor plus invoice number is the pair the duplicate guard searches on. It has to exist and be consistent.
- Your currency and size limitsThe allowed currency list and the file size caps are business settings, not technical ones.
- A named review ownerSomebody has to own the Needs Review label, or exceptions pile up in a place nobody is watching.
- Credentials and a daily capMail and model credentials, plus the cap that bounds daily spend.
Walkthrough transcript
Full narration from the walkthrough above. Captions are available in the player.
- 0:00
Every invoice and receipt landing in this inbox gets read, checked, and logged.
- 0:05
Nobody types anything.
- 0:07
It splits each email into attachments.
- 0:10
Only PDFs and images inside the size caps go through.
- 0:13
Anything unreadable, a HEIC photo or a Word doc, gets flagged and finance is told.
- 0:20
Nothing vanishes silently.
- 0:23
Files already in the ledger are skipped, and a daily cap keeps AI spend predictable.
- 0:28
Then Claude reads the document, treated as untrusted data, because a stranger sent it.
- 0:35
A schema guard checks what comes back.
- 0:37
Plain numbers, ISO dates, allowed currencies, and that subtotal plus tax equals the total.
- 0:43
Then it looks for the same vendor and invoice number already recorded, so nothing gets paid twice.
- 0:48
Every file gets a ledger row.
- 0:51
Recorded, needs review, or duplicate.
- 0:54
Doubtful items go to finance with a needs review label.
- 0:58
Everything handled is labelled processed, so it's never read twice.
- 1:03
Read. Checked. Logged. Never paid twice.
COMMON QUESTIONS
Questions people ask
about this workflow.
Does it work with scanned receipts and phone photos?
PDFs and images inside the configured size caps go through to extraction. Formats that cannot be read reliably, such as a HEIC photo or a Word document, are labelled and raised to finance instead of being skipped silently.
How does it avoid paying the same invoice twice?
Before a ledger row is written, the workflow searches the ledger for the same vendor and invoice number. A match is recorded with a duplicate status rather than being passed on for payment.
What stops the AI from inventing values?
A schema guard checks the extraction before anything downstream uses it: amounts must be plain numbers, dates must be ISO format, the currency must be on an allowed list, and subtotal plus tax must equal the total. Anything that fails is routed to human review.
Can an attachment contain instructions that hijack the AI step?
The document is handled as untrusted data, because it was sent by someone outside the business. Its contents are read as data, and the extraction that comes back is validated against a schema rather than acted on directly.
How are AI costs kept under control?
Two filters run before the model is called: files already in the ledger are skipped, and a daily cap limits how many documents are sent for extraction each day.
Does a person still check anything?
Yes. Items the checks could not clear are labelled Needs Review and finance is alerted. A named owner for that label is part of putting the workflow into service.
Which tools does the workflow connect?
n8n orchestrates the run, Gmail provides the trigger and the labels, Claude performs the extraction, and a spreadsheet-based expense ledger holds one row per file.
Build status
This article describes a reviewed workflow implementation and the structure shown in the walkthrough. Provider credentials, ledger access and end-to-end testing are configured per business. No measured savings, cost reductions or accuracy rates are claimed.
HAVE A PROCESS LIKE THIS?