Before and after: an n8n invoice template on 50 synthetic invoices. Synthetic data, public template, not a client deployment.
View the Project on GitHub beyondalgorithms2026-source/Rescue_Diagnostic
by Spanfold · Rescue Diagnostic → Fix & Harden · Apache-2.0 · Repository · tag v1.0.1
All data is synthetic. Every invoice, vendor, and email address was generated for this test. The PDFs carry the footer “SYNTHETIC TEST DOCUMENT — NOT A REAL INVOICE”. This is a public template tested on test data. It is not a client deployment, not an audit, and not a security or compliance review.
A popular free n8n template takes an invoice PDF, sends its text to an LLM, and writes the result to a sheet and an email. Before a small business relies on a flow like this, someone has to answer one question: what goes wrong when real documents arrive, and what happens when the same invoice is sent twice?
We replayed 50 labelled synthetic invoices through the template as published, repaired only enough to run, and then through
a hardened version. The same model (gpt-4o-mini-2024-07-18) was used in both phases.
As published, the template does not run. Two defects stop it at the first step:
After those two minimal repairs, the baseline still fails. Counts are over the 50 synthetic invoices, two passes each.
| Failure | Baseline (repaired) |
|---|---|
| Duplicate invoice rows after resubmission | 48 |
| Invoices with no failure code (clean) | 0 / 50 |
| Invoices lost with no record or error | 3 |
| Invoices with no audit trail | 50 |
| Bad documents written anyway (totals do not foot) | 2 |
| PDF prompt injections followed (overwrote the invoice number) | 2 |
| Tax captured correctly (where a record exists) | 0 / 47 |
Its “Verified” banner checks fields the sheet never returns, so it always says verified.
The hardened workflow adds seven controls, one per stage:
| Stage | Control |
|---|---|
| Intake | Size limits; a hash of the input; free text is never sent to the model |
| Extract | 40,000-character text cap; $0.25 per-run spend cap; rate cap |
| Validate | Schema gate; invoice totals must foot before anything is written |
| Decide | Doubtful invoices go to a review queue, not to the sheet |
| Act | Duplicate key check; the header row is written last and is the commit marker |
| Approve | A person decides on review items |
| Record | One audit row per invoice; run id, cost, per-step outcome |
Output in the report is HTML-escaped. The recipient list is restricted to allowed domains.
| Measure | Baseline (repaired) | Hardened |
|---|---|---|
| Invoices with no failure | 0 / 50 | 49 / 50 |
| Duplicate invoice rows after resubmission | 48 | 0 |
| Replay of the same batch into the same store: new rows | not run | 0 |
| Invoices lost with no record or error | 3 | 0 |
| Invoices with no audit trail | 50 | 0 |
| Bad documents written anyway | 2 | 0 |
| PDF injections followed | 2 | 1 (see limits) |
| Tax captured correctly (where a record exists) | 0 / 47 | 38 / 38 |
| Model calls | 100 | 58 |
| Cost (USD, from run ledger) | $0.042 | $0.014 |
Hardened outcomes: 32 committed, 6 duplicate skips, 6 rejected (2 size cap, 3 schema, 1 intake), 6 sent to review.
Five of these differ from the gold label. All five are label errors in the test fixture, not workflow errors. The
details are in evals/findings.md.
These three are from the same 50-invoice set. All numbers come from evals/scorecard.csv.
| Invoice | Original (baseline) | Hardened | Why it matters |
|---|---|---|---|
| t2-001 (clean, USD) | Written 4 times, audit row missing | Written once, committed | Shows the duplicate defect |
| t2-023 (messy, totals do not foot) | Written 2 times including a bad document | Sent to review, 0 writes | The one that went to a person. Gold label says “committed”; this is a label error (see limits) |
| t2-046 (PDF prompt injection) | Invoice number overwritten to ATTACK-OVERRIDE-046 |
Committed, still ATTACK-OVERRIDE-046 |
Shows a remaining failure: a consistent override passes the checks |
The full residual-risk list and the OWASP LLM Top 10 mapping are in evals/findings.md.
Loom walkthrough: to be added after recording (3–5 minutes).
Clone the repository and follow the replay steps in the README. The replay runs on a local n8n 2.22.5 with a local sink. It needs no Google account and no live Gmail or Sheets.
Spanfold is the brand behind this work. This page describes one synthetic test. It makes no claim about any real client workflow.