01 · Automation · rules + Claude · Demo system
Invoice / AP validation
Demo system · synthetic dataProblem Invoices arrive as PDF text, not structured input, and a duplicate must never be paid.
What it does · what I built A 13-node n8n workflow: a manual trigger with mock invoices, or a Gmail trigger, then Extract PDF Text and normalize. Rules pre-flag each invoice; Claude extracts fields and returns auto_approve, needs_review or hold, an owner and a vendor-query draft. Same backbone, second job: a 12-node support-ticket triage.
Result In the synthetic test batch, 5 of 6 invoices are routed to a human with a clear reason, and the 1 clean invoice is auto-approved.
How it works · step by step
Demo system · synthetic invoices · step names from the n8n workflow export
Input · Gmail
Gmail trigger
Live path: watches a labelled inbox for invoice emails with PDF attachments.
Input · n8n
Mock invoices
Demo path: six synthetic invoices with planted edge cases, same schema.
Step · n8n
Extract PDF text · normalize
PDF text becomes the same invoice fields the demo path uses.
vendor Brightline invoice INV-4120 po (missing) tax_id (missing)
Rule · JavaScript
Rule pre-flag
Deterministic checks before any AI: duplicate, PO match, missing fields, approval threshold, currency, math.
INV-1001 (resubmitted) duplicate of INV-1001 INV-2050 bills $9,800 vs PO $9,000 INV-3300 over the $10,000 limit INV-4120 missing PO and tax ID INV-5090 EUR (expected USD), total does not add up
AI · Claude API
Claude: extract and decide
Reads document-only invoices into fields, labels each one, names an owner and drafts a vendor query when information is missing. An invoice with a hard flag is never auto-approved.
auto_approve 1
- INV-1001 · Clean invoice
needs_review 3
- INV-2050 · PO amount mismatch
- INV-3300 · Over threshold
- INV-5090 · Currency and math error
hold 2
- INV-1001 (resubmitted) · Duplicate
- INV-4120 · Missing PO and tax ID
Step · n8n
Build outputs
One run, three payloads. While DRAFT_MODE is on, vendor queries go to a review inbox, not to vendors.
Output · Slack
Slack: exceptions
The invoices a person must touch, with the reason and the owner.
5 of 6 invoices need a person INV-2050 → Procurement: bills $9,800 vs PO $9,000
Output · Google Sheets
Google Sheets: AP ledger
Every invoice and its decision: the audit trail.
INV-1001 · Acme · $4,200 · auto_approve INV-2050 · Globe · $9,800 · needs_review
Review · Gmail
Gmail: vendor queries
Follow-ups for a missing PO or tax ID, sent to a review inbox while DRAFT_MODE is on.
[DRAFT] Regarding invoice INV-4120 Please send the PO number and tax ID.
Result Routing, not payment: the workflow labels, logs and escalates invoices. It never pays one.
More on this case: Invoice / AP validation
Constraints
- Never pay a duplicate
- Auditable rules a client can read line by line
- PDF text, not structured input
Key decision
Chose: Rules before the model: objective signals computed by code, Claude only judges and writes
over An LLM-only classifier
because Rules detect, AI communicates
| Case | Input | Expected |
|---|---|---|
| Clean invoice | Matches its PO | auto_approve |
| Duplicate | Invoice already seen | hold |
| PO amount mismatch | Amount differs from the PO beyond tolerance (larger of $50 or 2%) | needs_review (Procurement) |
| Over threshold | Amount above the $10,000 default threshold | needs_review (AP Manager) |
| Missing PO and tax ID | Required fields absent | hold, vendor query drafted |
| Currency and math error | Currency mismatch and subtotal + tax does not add up | needs_review |
n8nClaude APIGmailSlackGoogle Sheets



