Catch Repeat Vendor Invoices With Claude

- You need
- Invoices, purchase orders and receipts as CSV
- Tested with
- Claude Sonnet 5.5, made-up data, 5 Nov 2026
- Result
- 120 of 120 match the key as written; 2 hyphen repeats pass
Four rules, 120 invoices
We gave Claude four rules for holding repeat vendor invoices before payment. All 120 of its decisions matched our own key: 101 approved, 19 held.
Two invoices with a dropped hyphen, R093 and R094, passed because the rule for the invoice number ignored only capital letters and spaces.
What you need
| File | What it holds |
|---|---|
vendor_invoices.csv (120 invoices) | Vendor, invoice number as typed, date, PO, quantity. In date order |
purchase_orders.csv (110 POs) | Vendor, item and ordered quantity. One line per PO |
goods_receipts.csv | Quantity received per PO |
Claude's ten-step plan
I work in accounts payable. Before an invoice goes to payment I need a decision on it: approve or hold. I have three files: - vendor_invoices.csv: invoices received (invoice_id, vendor_id, invoice_no, invoice_date, po_no, qty, unit_price, amount). The file is in date order. - purchase_orders.csv: one line per purchase order (po_no, vendor_id, vendor, item, qty_ordered, unit_price) - goods_receipts.csv: quantity received per purchase order (po_no, qty_received) My rules, checked in this order. An invoice that fails a rule is held, and the report names the first rule it fails. 1. The PO must be on purchase_orders.csv and belong to the vendor on the invoice. 2. The invoiced quantity cannot be more than the quantity received on that PO. 3. A vendor can use an invoice number once. If the same vendor has already sent an invoice with the same number, hold the new one. The same number means the same after ignoring capital letters and spaces around it. The same number from a different vendor is fine. 4. If earlier approved invoices already cover the full quantity ordered on a PO, hold any further invoice for that PO. Go through the invoices in file order. Do not write code yet. Break the job into numbered steps. For each step say what it checks, and what the tool does with an invoice it cannot decide. Then list anything in my rules that is unclear.
In the first session Claude gave ten steps and worked the file by hand first. It predicted 101 approved and 19 held, and named the held invoices: three on rule 1, six on rule 2, eight on rule 3 and two on rule 4.
The script produced the same list.
It also asked seven questions, and two were about the gaps in our rules. R093 and R094 are VI4921 and VI4934, repeats of VI-4921 and VI-4934 without the hyphen. Claude said the rule would approve them and asked whether we wanted hyphens ignored.
It also saw that rule 2 compares each invoice only with the quantity received, so two invoices of 60 on 100 received would both pass.
We did not answer, and prompt 2 said to use the plan, so both sessions followed our wording and approved R093 and R094.
A 188 line script, 120 of 120
Good. Use that plan. Write one Python script, standard library only, that reads the three files and writes decisions.csv with one row per invoice and these columns: invoice_id, decision, rule, reason. - decision is one of: approve, hold - rule: the number (1 to 4) of the first rule the invoice fails, empty when approved - reason: one short sentence an AP clerk can read Never change my input files. Run it, then show me the count of invoices per decision and every invoice that is held.
Claude Sonnet 5.5 (claude-sonnet-5-5) ran both prompts as two turns on 5 Nov 2026. (The test harness also made one call to Claude Opus 5.5 per session.) The script is 188 lines of standard library Python.
It approved 101 invoices and held 19, and all 120 decisions matched our own key, which we wrote from the four rules as worded, rule number included. A second session wrote a 172 line script and scored 120 of 120 too.
| Invoice | Vendor | Number as typed | Decision | Note |
|---|---|---|---|---|
| R024 | V04 | VI-4892 | approve | First use of VI-4892 by this vendor |
| R108 | V01 | VI-4892 | approve | Same number, another vendor. Fine by the rule |
| R038 | V05 | VI-4921 | approve | First use of VI-4921 |
| R093 | V05 | VI4921 | approve | The hyphen is missing. The rule ignores case and edge spaces only |
| R049 | V06 | Vi-4811 | hold rule 3 | Capital V, lower case i |
| R062 | V06 | VI-4795 | hold rule 3 | A space in front |
| R057 | V04 | VI-4853 | hold rule 3 | Same number on a different PO |
| R087 | V06 | VI-5017 | hold rule 2 | Also a repeat, but 40 invoiced against 30 received |
Rule 3 reads: a vendor can use an invoice number once. If the same vendor has already sent an invoice with the same number, hold the new one. The same number means the same after ignoring capital letters and spaces around it.
The same number from a different vendor is fine. Rule 3 held eight repeats in our data: six that differ by case or spacing, and two on a different PO. It approved the three numbers that two different vendors both used.
R087 and R109 are repeats too, but they also bill more than was received, and rule 2 comes first, so the report names rule 2.
120 planted invoices, then 18 small files
1. The planted key
We built the data from these cases: 79 plain invoices, six repeats that differ by case or spacing, two repeats on another PO, a second invoice on a PO already invoiced in full, three numbers shared by two vendors and two numbers with the hyphen dropped.
The key says approve or hold, and which rule, for each invoice. A script compares the output with it.
The vendors, numbers and quantities are invented, and the key follows our reading of the four rules.
2. Change the rules and run it again
We told Claude about the two gaps: rule 4 should hold an invoice when the quantity already approved plus its own is more than the quantity ordered, and hyphens and spaces inside the number should be ignored.
It wrote a 189 line version that did both. R093 and R094 became holds under rule 3, and on a test PO ordered at 100, an approved 60 followed by another 60 was held.
We ran 18 small files through the first script, the second session's script and the new version:
| What we sent | First script | Second session | First script, after the change |
|---|---|---|---|
VI-5000 then vi-5000, or then VI-5000 with a trailing space | Held, rule 3 | Held, rule 3 | Held, rule 3 |
| The same, with a non-breaking space at the end | Held, rule 3 | Held, rule 3 | Approved |
VI-5000 then VI5000, or VI- 5000 | Approved | Approved | Held, rule 3 |
| Two invoices of 60 on a PO ordered and received at 100 | Both approved | Both approved | Second held, rule 4 |
| An invoice for a quantity of 0 | Held, rule 2 | Approved | Held, rule 2 |
| A file whose dates are out of order | Stops with a message | Processes in file order | Stops with a message |
| A held invoice corrected and sent again under the same number | Held, rule 3 | Held, rule 3 | Held, rule 3 |
| An amount that is not quantity times price | Approved | Approved | Approved |
After the change, VI-5000 followed by VI-5000 with a non-breaking space gets through. The first script held it, because Python's strip removes that character. The new version replaces only ordinary spaces and hyphens.
3. Open questions
- Should
VI-05000count as a repeat ofVI-5000? It gets through today. - Should a corrected resend of a held invoice under the same number be held again? Ours holds it under rule 3.
Nothing here checks that the amount equals quantity times price.