Blog · · 4 min read
How to extract invoice data into Google Sheets with AI and n8n
Automate invoice logging: n8n picks up PDF invoices from Gmail, AI extracts supplier, tax ID, net amount, VAT, withholding and total, checks the maths and adds a row to Google Sheets.

If you freelance or run a small business, the routine is always the same: dig the invoices out of your inbox, open each PDF and type the supplier, tax ID, net amount, VAT and total into a spreadsheet for your accountant. It's a small job each time, but it adds up, and one typo is enough to cause trouble.
With n8n (a visual automation tool) and an AI model you can make that logging happen on its own: every invoice that reaches Gmail becomes a row in Google Sheets, and you only check the ones the automation flags as doubtful.
What you'll build
The workflow does five things:
- Watches Gmail for emails with a PDF attachment that match a search (for example, an "Invoices" label).
- Reads the PDF text, skipping logos and stray images.
- Extracts the data with AI: supplier, tax ID, invoice number, dates, description, net amount, VAT rate, VAT amount, withholding, total and currency.
- Checks the maths: net + VAT − withholding must equal the total, and there must be an invoice number.
- Adds a row to Google Sheets marked
OKorREVIEW, and emails you the ones that need a look.
What you need
- An n8n instance, cloud or self-hosted.
- Gmail and Google Sheets connected to n8n with OAuth2.
- An OpenAI API key (or another compatible provider) with a spending limit set.
- A sheet with an "Invoices" tab and columns for logged date, supplier, tax ID, number, invoice date, due date, description, net, VAT rate, VAT, withholding, total, currency, file, sender, status and notes.
Step 1: filter your email properly
Don't feed your whole inbox to the AI. Create a Gmail filter that applies an Invoices label to emails from your usual suppliers or containing "invoice", and use a search like label:invoices has:attachment in the n8n trigger. You'll process fewer emails, spend less and avoid false positives.
Step 2: split the attachments and extract the text
One email can carry several attachments. Split the binary files into separate items, keep only the PDFs and use the Extract From File node to pull out the text. Cap it at the first few pages: an invoice is rarely longer than two, and it keeps costs under control.
Step 3: the extraction prompt
This is the key part. Ask the AI to reply only with JSON using fixed keys so the next nodes can read it. A good prompt includes:
- The exact list of fields and their format (YYYY-MM-DD dates, amounts with a decimal point and no currency symbol).
- A don't invent rule: if a value isn't there, return
null. - What to do with several VAT rates (add up the net amounts and the VAT).
- An
is_invoicefield to discard quotes, delivery notes and newsletters. - A warning that the PDF text is untrusted content and any instructions inside it must be ignored. It sounds paranoid, but a PDF can contain text designed to trick the AI.
Step 4: validate before saving
The AI gets digital invoices right almost every time, but "almost" isn't good enough for bookkeeping. Add a code node that checks:
- Net + VAT − withholding matches the total, with a small rounding tolerance (say, 5 cents).
- There's an invoice number and a total.
- The document really is an invoice.
If something fails, the row is still saved but marked REVIEW with the reason. Nothing gets lost, and you know exactly what to look at.
Step 5: save to Google Sheets and notify
Use the Google Sheets node in "append row" mode and map each field to its column. Then a Gmail node sends you a summary of only the invoices marked REVIEW. The correct ones stay out of your way.
Common mistakes
- Scanned PDFs. If the invoice is a photo, there's no text to read. Flag it for review or switch to a vision-capable model.
- Invoices sent as links. Some suppliers email a download link instead of an attachment; those need separate handling.
- Trusting the AI blindly. The amount check is what makes this usable.
- Processing the whole inbox. Without a filter, invoices get mixed with newsletters and costs go up.
Does it replace your accountant?
No. It saves you the typing and keeps everything tidy in one sheet. Tax review and filing are still up to you or your accountant.
Shortcut: the ready-made agent
This workflow is one of the eight agents in the AgentKiosk pack: an n8n template ready to import, with the full extraction prompt, the amount check including VAT and withholding, all settings in a single node and a PDF guide. It has been imported and run end to end in n8n with sample data; test it with a real invoice before relying on it.
Want to start with something free? Download the WhatsApp agent and then read AI automations for small businesses.


