Let the model read the invoice, not approve it: an n8n pattern for AP automation
Most "AI invoice automation" demos stop at the fun part: a model reads a PDF and spits out JSON. The hard part is what happens next. Who decides the invoice gets paid? What stops a fake "we changed our bank details" email from going straight through? We built an accounts payable workflow in n8n around one rule: the model reads the invoice, code decides what happens to it. The model never approves…
In this article, the author outlines a pattern for automating accounts payable (AP) processes using the n8n workflow platform. The key points are:
1. The model only reads invoice data, never making approval decisions. A separate code node handles routing decisions based on the extracted invoice information.
2. The workflow begins with a Gmail trigger that processes each email containing an attached PDF invoice as a separate execution, ensuring one run per invoice.
3. The PDF is stored in Google Drive, then processed by Claude to convert it into structured JSON fields using a custom extraction prompt.
4. The extracted fields are normalized through functions to account for inconsistencies in vendor names, invoice numbers, and IDs. This helps match the invoice to existing records accurately.
5. The routing logic determines the next steps based on various checks:
- If no holds or notes exist, the invoice either gets auto-approved, requires manual approval in Slack, or is held for further review.
- Holds can be triggered by vendor/sender mismatches, bank detail discrepancies, or phrases indicating potential fraud.
- Arithmetic checks ensure the invoice's subtotal plus tax equals the total, and line items sum correctly.
- Duplicates are identified through vendor, invoice number, and date comparisons.
- PO matches verify that the invoice aligns with an existing purchase order.
6. Approvals are handled via Slack, with automatic approval for small, PO-matched invoices without notes. Larger or more complex invoices require multi-level approvals, ensuring separation of duties between approvers.
7. Held invoices are categorized into three types: fraud risk (alerted to finance), fixable issues (requiring a corrected invoice), or other items needing manual review.
8. Gmail labels reflect the final outcome (approved, held, rejected), effectively turning the AP inbox into a visual status board for the process.
The article emphasizes the importance of separating data extraction from decision-making, handling each invoice as an individual execution, and implementing robust checks to prevent fraudulent or incorrect payments.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.