Field SOP
Field SOP

Invoice Processing Automation Workflow: From Receipt to Ledger, Fully Automated

An n8n workflow for invoice processing automation: email/upload trigger -> extract attachment -> OCR/LLM field extraction -> validate -> IF pass write to finance system else human review -> archive. Includes compliance notes (sensitive financial data, recommend local OCR + private LLM, per local tax regulations). Includes a .json template download.

Published August 2, 20265 min read
<!-- workflow-invoice-processing-automation | resource | Invoice Processing Automation Workflow: From Receipt to Ledger, Fully Automated -->

One of the most tedious tasks for finance and admin teams: manually keying dozens or hundreds of invoices and receipts into the accounting system every month. Transpose a digit in the amount, miss a character in the tax ID, mix up the month in the date — and reconciliation becomes a treasure hunt through stacks of paper originals. End-of-month expense reports pile up, and invoices arrive from everywhere: supplier emails with PDF attachments, employees uploading photos of receipts, expense platforms exporting electronic invoices — none in a uniform format, so even copy-paste barely helps.

This n8n workflow template turns invoice processing from "manual data entry" into a fully automated pipeline: email arrives → attachment extracted → LLM pulls out invoice number / amount / date / tax ID / category → Code node validates and formats → valid items auto-post to the financial system, invalid ones route to a human-review notification, and everything gets archived with a status tag.

Workflow Chain

Email Read trigger (IMAP, downloads attachments) → Extract from File (PDF parse / image OCR) → HTTP Request calls LLM to extract fields (invoice_no / amount / date / tax_id / category) → Code node validates + formats (amount to number, date normalized, required-field check) → IF validation passes → True branch: HTTP Request writes to financial system (finance API / Google Sheets / Feishu Bitable) → archive record (Set node tags status); False branch: HTTP Request notifies for manual review (Slack webhook / email) → archive record.

Download Template

Setup Steps

  1. Import: n8n → Workflows → Import from File, select workflow-invoice-processing-automation.json
  2. Email Read node: Configure the IMAP connection (email address, password / app password, IMAP server e.g. imap.gmail.com:993), enable downloadAttachments. Set up a dedicated "invoices" folder in the mailbox and use a label/filter so only invoice emails land there — don't let the full inbox trigger the workflow on every email
  3. Extract from File node: For PDF invoices, select the pdf operation. For photographed/scanned receipts, n8n's native extractFromFile has limited image support — use an HTTP Request to call an OCR API (Google Vision, AWS Textract, Alibaba Cloud OCR, Tencent Cloud OCR), or skip this node and use a vision-capable LLM (GPT-4o, Qwen-VL) to read the image directly
  4. LLM extract fields node: Enter your API key (DeepSeek / Kimi / Qwen / any OpenAI-compatible endpoint). The prompt must specify the fields to extract: invoice_no, amount (state whether tax-inclusive), date, tax_id, category. Require JSON-only output — no prose
  5. Code validation node: Three core steps — parse the LLM's JSON response, validate required fields (invoice_no, amount, and date must be non-null; amount must be a positive number), and format (normalize date to YYYY-MM-DD, convert amount to Number, strip whitespace from tax_id). Store the result in a valid field for the IF node
  6. IF node: Branch on the valid field — true goes to the posting branch, false goes to review
  7. Write to financial system node: Pick your target — finance API via HTTP Request POST; Google Sheets via the official n8n Google Sheets node (append row); Feishu Bitable via HTTP Request calling the OpenAPI
  8. Notify for manual review node: Configure a Slack incoming webhook URL. Include the failure reason (which field is missing) and the invoice number in the message so humans can locate it quickly. No Slack? Send an email notification instead
  9. Archive node: The Set node tags each record — "posted" for valid items, "needs review" for flagged ones. Optionally chain a Move File node to move the original attachment to an archive directory
  10. Test run: Send a test email with an invoice attachment to the inbox, trigger the workflow manually, and verify the new record appears in your financial system / spreadsheet with the correct amount and date

Companion Prompt (LLM Field Extraction)

Prompt
You are an invoice field extractor. From the invoice text below, extract these fields:
1. invoice_no: invoice number (alphanumeric)
2. amount: total amount including tax (numeric, no currency symbol)
3. date: invoice date (YYYY-MM-DD format)
4. tax_id: seller's tax ID
5. category: expense category (e.g., meals / travel / office supplies / software / consulting)
Output JSON only, with fields: invoice_no / amount / date / tax_id / category.
If a field is not found in the text, set it to null. Do not output any explanation.
Invoice text:
{{ $json.data }}

Pitfalls

  • LLM confuses tax-inclusive vs tax-exclusive amounts: Many invoices list both a pre-tax subtotal and a tax-inclusive total. The prompt must specify which one to extract (posting usually needs the tax-inclusive total), or the LLM will pick one at random and amounts won't reconcile
  • PDF invoice layouts vary wildly: Electronic invoice PDFs from different vendors place the invoice number in different corners. LLM extraction is more robust than regex, but it occasionally misreads "invoice code" as "invoice number." Add a format check in the Code node (e.g., Chinese invoice numbers are typically 20 digits)
  • Poor OCR quality on photographed receipts: Phone photos of receipts are often skewed, glared, or partially blurred. Pre-process the image (crop, deskew, enhance contrast) before OCR for a noticeable accuracy boost. Or use a vision-capable multimodal LLM (GPT-4o, Qwen-VL) to read images directly and skip the OCR step
  • Full-inbox triggers flood the workflow: Email Read pulls all new emails by default. Set a mailbox-side filter to route only invoice emails to a dedicated folder, and have n8n watch that folder only — otherwise every email triggers an LLM call, burning time and API credits
  • Duplicate invoices post twice: The same invoice forwarded twice gets posted twice. Add a deduplication check in the Code node — query the financial system / sheet for an existing invoice_no and skip if found

Compliance Notes

  • Invoices contain sensitive financial and tax data: Tax IDs, amounts, and counterparty information are enterprise-sensitive. Sending them to a cloud LLM means transmitting financial data to a third party — assess data-transfer and cross-border compliance risks first
  • Prefer local processing: For data-sensitive scenarios, use local OCR (PaddleOCR / Tesseract) paired with a self-hosted LLM (e.g., Qwen2.5 via Ollama) so data never leaves your network
  • Electronic invoices have legal retention requirements: In many jurisdictions, electronic invoices must be archived in their original form for a statutory period (e.g., China's Accounting Archives Management Measures). Automation replaces the data-entry step, not the approval workflow or legal retention — original files must still be preserved, approval flows followed, and tax filings made per local tax law
  • Consult local tax regulations: Invoice compliance varies by country and region (EU VAT invoices, China's special VAT invoices, US 1099 forms, etc.). This workflow provides the technical pipeline only — for specific compliance requirements, consult your finance or legal team

References

This article is AI-assisted and human-edited. Last updated: 2026-08-02

Related