Match Messy Remittance References With Claude

- You need
- Bank lines and open invoices as CSV
- Tested with
- Claude Sonnet 5.5, made-up data, 5 Nov 2026
- Result
- 60 of 60 bank lines match our key
One rule, 60 bank lines
We gave Claude one rule for reading an invoice number a customer typed into the payment reference, plus 60 bank lines, and it read every typing correctly on the first try.
On 24 test cases we had not put in the data, the first script paid INV-20004 on references such as ORDER 20004 and PAYMENT 20004.50.
What you need
Two CSV files
| Your file | Columns used |
|---|---|
Bank lines, as in our bank_lines.csv (60 lines) | line_id and reference. Date, amount and payer are in the file but the rule forbids using them |
Open invoices, as in our open_invoices.csv (62 invoices) | invoice_no. The numbers run INV-20002 to INV-20088 with gaps |
Prompt 1 asks for a plan, with no code
Attach both files and paste this. We do not publish the data, so your numbers will differ from ours.
I work in accounts receivable. When a customer pays, I need to know which open invoice the bank line pays. I have two files: - bank_lines.csv: payments from the bank (line_id, date, amount, payer, reference) - open_invoices.csv: invoices still unpaid (invoice_no, customer_id, customer, invoice_date, open_amount, currency) Customers type the reference by hand, so the same invoice shows up written in different ways. My rules: 1. The reference decides. A bank line pays an invoice only when its reference names that invoice. 2. Never use the amount or the payer name to choose an invoice. 3. A reference can name more than one invoice. Then the line pays all of them. 4. If the reference names an invoice that is not on the open list, or names none, the line goes to a person. Do not write code yet. Break the job into numbered steps. For each step say what it checks, and what the tool does with a line it cannot decide. Then list anything in my rules that is unclear.
Claude gave seven steps: check the files, clean the text, pull out every run of digits, compare each run to the open list whole, decide the line, check that no invoice is paid twice, and tie the counts to 60.
It counted the file by hand before running anything and said 48 lines would pay 54 invoices and 12 would go to a person. The finished script gave the same numbers.
It also asked seven questions. Three concern references, and Claude picked an answer for each:
- Does a bare five digit number with no INV in front count as naming an invoice? Claude assumed yes.
- Should a number that looks like a typo of an open invoice, such as
INV-2004, go to a person? Claude assumed yes and never repaired it. - What if a reference names one open invoice and one that is not open? Claude assumed the whole line goes to a person.
We answered none of the seven, so Claude used its own default for each.
Ask Claude to build it
Good. Use that plan. Write one Python script, standard library only, that reads both files and writes matches.csv with these columns: line_id, status, invoice_nos, reason. - status is one of: matched, needs_review - invoice_nos: the invoice numbers as written in open_invoices.csv, joined with | when the line pays several - reason: one short sentence a collector can read Never change my input files. Run it, then show me the count of lines per status and every line that is needs_review.
Claude Sonnet 5.5 (claude-sonnet-5-5) ran both prompts as two turns on 5 Nov 2026. It wrote a 183 line Python script with the standard library only.
A script compares its output with our key line by line, and it matched 60 of 60 lines. The key is the list of right answers we made when we built the data.
| Line | Reference as the customer typed it | What the script did |
|---|---|---|
| B009 | inv20016 | matched: INV-20016 |
| B013 | INV 20052 | matched: INV-20052 |
| B004 | PAYMENT 20088 BATCH 9525 | matched: INV-20088 |
| B002 | INV 20079 & 20037 | matched: INV-20079 and INV-20037 |
| B016 | INV-2004 | needs review |
| B042 | INV-200565 | needs review |
| B030 | PO 120043 | needs review |
| B005 | (blank) | needs review |
The 42 lines that name one invoice use eight typings: INV-20004, inv20004, INV 20004, INV20004, INV#20004, Inv. 20004, INVOICE 20004 THANK YOU and a bare 20004 next to a batch number. Six more lines name two invoices.
Six name a number that is not on the open list, and six have no reference. Three of those six carry an amount equal to an open invoice, and the script left all three for a person.
A second session with the same two prompts wrote a different script and also matched 60 of 60.
60 planted lines, then 24 unplanted cases
1. Try references that are not in the data
We ran 24 test cases of one or two lines each. The first script paid an invoice on references where the number sat behind another label or carried a decimal, as in the first four rows below.
The first script paid these because Claude's plan counts a bare five digit number as an invoice. The second session's script gave the same answers on all 24.
In the first script, any number that equals an open invoice pays it, unless it follows PO or BATCH.
| Reference | First script | After we told Claude about it |
|---|---|---|
ORDER 20004, SO-20004, CR-20004 | Paid INV-20004 | Sent to a person |
PAYMENT 20004.50 (an amount) | Paid INV-20004 | Sent to a person |
ORDER NO 20004, REFERENCE 20004 | Paid INV-20004 | Paid INV-20004, still |
REF 20004 20007 | Paid INV-20004 and INV-20007 | Paid INV-20007 only |
INV-20004A | Paid INV-20004 | Paid INV-20004, still |
INV-020004 | Sent to a person | Sent to a person |
INV 20004-20007 | Paid both | Paid both |
PO 20004 | Sent to a person | Sent to a person |
We then told Claude, in a third turn, that a number after ORDER, SO, CHECK, CHQ, CR or REF is not an invoice and that a number with a decimal point and digits is an amount.
It wrote a 196 line version that fixed those. It did not catch ORDER NO 20004, because the word NO sits between the label and the number.
It now pays only INV-20007 on REF 20004 20007, because a label covers only the number right after it. The fix created a silent partial payment there. A comma decimal such as 20004,50 still pays INV-20004 in both versions.
Two more answers from that turn: INV-20004A is still read as INV-20004, and INV 20004-20007 is read as two invoices, not a range.
On our 60 lines the second version changed nothing, because none of the 60 lines has one of those six words in front of a number, or a decimal point.
2. Questions the script leaves open
- Is a bare number enough, or must INV come first?
- Which words in front of a number mean it is not an invoice? Ours ended at eight, two from the first script and six from the change.
- If a reference names two invoices and one is already paid, does the line wait for a person or pay the open one?