ChatFin/Match Bank Debits by Payment ID With Claude

Match Bank Debits by Payment ID With Claude

By Ashok ManthenaPublished 5 Nov 20266 min read
Three rows of bank_statement.csv go into Claude: BK-038 for ACH PAY-30, BK-057 reading CK 20364 PAID and BK-055 a credit reading RETURN PAY-400. In rec_status.csv BK-038 is cleared against PAY-30, while BK-057 and BK-055 are other and clear nothing. A note reads 123 of 123 rows match our key.
You need
AP payments and the bank statement as CSV
Tested with
Claude Sonnet 5.5, made-up data, 5 Nov 2026
Result
123 of 123 rows match our key

Five rules, 123 rows

We gave Claude five rules for finding each issued payment's ID on the bank statement, and its script matched our own key on all 123 rows.

Four checks show on the statement under another wording and still sit as outstanding, because the bank did not write the word CHECK.

The two CSV files

Files for the payment ID test
FileWhat it holds
ap_payments.csv (62 payments)ID, vendor, method, check number, amount, issue date. 54 are ACH and 8 are checks
bank_statement.csv (61 lines)Date, description and amount. A debit is negative and a credit positive

Claude's eight-step plan

Prompt 1: plan
I work in accounts payable. Every month I have to find out which payments we issued have cleared the bank. I do it by hand and it takes a day.

I have two files:
- ap_payments.csv: payments we issued (payment_id, vendor, method, check_no, amount, issue_date). Method is ACH, WIRE or CHECK.
- bank_statement.csv: the bank's lines (line_id, date, description, amount). A debit is negative, a credit is positive.

My rules:
1. A debit clears a payment when its description names the payment_id as a whole ID. A check payment is cleared when the description has the word CHECK followed by the check number. Never match on the amount.
2. The debit amount must equal the payment amount to the cent. If a debit names a payment but the amount is different, the payment is amount_mismatch, not cleared.
3. A credit never clears a payment.
4. If a second debit names a payment that has already cleared, the second debit is a duplicate.
5. A payment with no clearing debit is outstanding.

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 or a payment it cannot decide. Then list anything in my rules that is unclear.

Claude warned that a plain text search would clear PAY-3, PAY-5, PAY-7 and PAY-9 using the debits for PAY-30, PAY-50, PAY-70 and PAY-90, and said IDs must be matched whole.

Before running anything it predicted 40 cleared, 3 amount mismatches and 19 outstanding payments, and 5 duplicate debits. The script gave the same numbers.

Four of our eight checks appear on the statement as CK 20127 PAID, CHQ 20147, CK 20364 PAID and 20801 PAID. The amounts equal the payments to the cent.

Rule 1 asks for the word CHECK, so Claude said they would stay outstanding and asked which abbreviations should count.

The plan raised seven open questions and we answered none. Prompt 2 said to use the plan, so Claude followed the rule as written, in the first session and in the second.

A 235 line script, 123 of 123 rows

Prompt 2: build and run
Good. Use that plan. Write one Python script, standard library only, that reads both files and writes rec_status.csv with one row per payment and one row per bank line, and these columns: item, kind, status, matched_to, reason.
- item is the payment_id or the line_id; kind is payment or line
- status for a payment: cleared, outstanding or amount_mismatch
- status for a bank line: cleared, amount_mismatch, duplicate or other
- matched_to: the line_id for a payment, the payment_id for a line, empty when there is none
- reason: one short sentence an accountant can read
Never change my input files. Run it, then show me the count of payments per status, the count of lines per status, and every line whose status is not cleared.

Claude Sonnet 5.5 (claude-sonnet-5-5) ran both prompts as two turns on 5 Nov 2026. The script is 235 lines of standard library Python. It cleared 40 payments, flagged 3 amount mismatches and left 19 outstanding.

All 62 payment rows and all 61 bank line rows matched our own key, which we wrote from the five rules. A second session wrote a 228 line script with the same result.

Eight of the 123 rows and the first script result
ItemAs the bank or the payment file has itAmountResultNote
BK-038ACH PAY-30 GANNET OFFICE FURNITURE-13069.65cleared PAY-30Names PAY-30, and PAY-3 is also a payment
PAY-3ACH4004.04outstandingNo debit names it. Inside PAY-30 is not a match
BK-004CHECK 20728-19455.66cleared PAY-203The word CHECK, then the check number
BK-057CK 20364 PAID-5282.92otherThe check number, but CK and not CHECK
PAY-204CHECK 203645282.92outstandingA debit with this check number and amount is on the statement, worded CK. Still outstanding by our rule
BK-055RETURN PAY-400 THISTLE RAIL SERVICES4421.22otherA credit that names PAY-400
BK-010WIRE OUT PAY-502 WRENBURY PALLETS-9198.95amount_mismatch PAY-502One cent off PAY-502
BK-052ACH DEBIT PAY-300 GANNET OFFICE FURNITURE-2881.92duplicate PAY-300The second debit for PAY-300

Rule 1 reads: a debit clears a payment when its description names the payment_id as a whole ID. A check payment is cleared when the description has the word CHECK followed by the check number.

Never match on the amount. The four IDs that sit inside longer ones (PAY-3 in PAY-30, and three more) all stayed outstanding, and so did the four checks that the bank wrote another way.

Five payments were debited twice. The script cleared the earlier debit and called the later one a duplicate. Where the date order and the file order disagreed, it used the date, and its reason column names the earlier debit and its date.

123 planted rows, then 28 cases

1. The planted key

We built the data with the cases in it: four short IDs inside long ones, eight checks (four written with CHECK and four not), five double debits, three credits that name a payment and three debits one cent off.

The vendors, IDs and amounts are invented, and the key is our own reading of the five rules.

2. 28 cases with descriptions of another kind

We ran 28 cases, each a payments file and a statement file, through both scripts. The two sessions agreed on all but two, and the table shows eight of them.

Payment ID edge cases, first and second session
What we sentFirst sessionSecond session
PAY1, PAY 1 or PAY-1A in the descriptionNot clearedNot cleared
PAY-1. or PAY-1/HALLAMClearedCleared
CHECK #20101, CHECK NO 20101 or CHK 20101Not clearedNot cleared
CHECK 201015 for check number 20101Not clearedNot cleared
One debit that names PAY-1 and PAY-2Neither clearedNeither cleared
A debit of 99.99, then one of 100.00, for a payment of 100.00Payment cleared, first debit "other"Payment amount_mismatch
A debit of 100.00, then one of 60.00Second debit "other"Second debit duplicate
A debit with a zero amount that names the paymentNot clearedNot cleared

In 27 of the 28 cases, anything the scripts would not clear was left visible: a description they could not read became an "other" line and the payment stayed outstanding.

In the 28th, a payment ID repeated in the payments file, both scripts stopped with no output and an error message.

The two sessions differed where our rules are silent or can be read two ways: a debit with the wrong amount followed by the right one, and a second debit with a different amount.

3. Four open questions

  • Which words in front of a check number count?
  • Does PAY1 or PAY 1 name PAY-1?
  • When a debit names a payment with the wrong amount and a later debit has the right one, which counts?
  • A credit that names a payment leaves it outstanding when no debit exists, and leaves it cleared after a debit. Do you want a returned status?