LLMs misread bank statements. Here's how we catch it with arithmetic.
Every PDF bank statement carries its own answer key. The running balance column, plus the summary box (opening balance, total in, total out, closing balance), let you check any extraction using arithmetic alone, with no
Every PDF bank statement carries its own answer key. The running balance column, plus the summary box (opening balance, total in, total out, closing balance), let you check any extraction using arithmetic alone, with no second model and no human in the loop.
I build Bank Statement Scanner (bankstatementscanner.com), which turns statement PDFs into Excel/CSV. Like most tools in this space we use an LLM for extraction. It's right most of the time, but "most of the time" isn't acceptable for financial data. These are the checks we run on every statement.
The balance chain
Between any two printed balances, the rows in between must explain the step:
previous_balance + credits - debits == next_balance # checking / savings
previous_balance - credits + debits == next_balance # credit cards (sign flips)
If a step doesn't add up, the error is pinned to the rows between those two balances, rather than "somewhere in a 14-page statement".
The size of the gap tells you what went wrong
Let gap = printed_balance - expected_balance, and let net be one row's signed effect. Then:
| Gap | Likely cause |
|---|---|
gap == -2 * net |
that row was read with the wrong direction (debit as credit) |
gap == -net |
that row was read twice |
| anything else | a row is missing, worth abs(gap), in direction sign(gap)
|
def hint_for_break(rows, brk, sign):
gap = brk["gap"]
candidates = []
for i in brk["rows"]:
net = signed_amount(rows[i])
if net == 0:
continue
if close(gap, -2 * sign * net):
candidates.append(("flipped_type", i))
elif close(gap, -sign * net):
candidates.append(("duplicate_row", i))
if len(candidates) == 1:
return candidates[0]
if candidates:
return None # ambiguous: don't guess
return ("missing_row", brk["from_row"], brk["to_row"], abs(gap))
Two details matter in practice:
- Return nothing when it's ambiguous. If two rows could both explain the gap, a confident wrong hint is worse than no hint.
- Identical duplicates are the exception. If the candidates are the same date, description and amount, it doesn't matter which copy you flag. Point at the later one.
The summary box catches what the chain can't
Some statements print no running balances. For those, compare the extracted totals against the summary box: the opening balance, total money in, total money out and closing balance all have to match. We also check that the summary box is consistent with itself, because OCR can misread the summary too.
Say "can't check", never "passed"
If a statement prints no balances and no summary, or covers several accounts on one PDF, we show "can't check". Reporting those as passed would be the easiest way to lose a bookkeeper's trust.
Across months
The closing balance of March should equal the opening balance of April. Grouping saved statements by account (last four digits) and linking them month to month surfaces missing months and balances that don't carry over. That catches problems no single-statement check can.
What this doesn't do
None of this is book-to-bank reconciliation against your ledger. It answers a narrower question: did the rows we extracted add up to what the bank printed? It's cheap and deterministic, and it catches the failure modes LLM extraction actually has.
If you're building something similar, steal the gap table. If you just have PDFs to convert, the first 10 pages are free with no account at bankstatementscanner.com.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.