How to turn bank statements into JSON with Claude¶
Long statements lose rows. The balance tells you where.
A statement is one table that runs for pages, and a single model call can stop early or skip lines without
saying so. On our long-document test (six long reports) Reducto's extraction returned 9.1% of the table rows;
ReadAnyDoc with
Claude Haiku, which reads in parts and checks row counts, returned 56.4%. Neither is 100%, which is why the
check at the end of this page matters more than the tool.
Four steps. The first and the last work with any way of calling Claude.
| Step | Why |
|---|---|
| 1. Fix the shape of a transaction | one sign convention, dates as printed, balance optional |
| 2. Read the statement in parts, not in one prompt | long lists get cut short in a single answer |
| 3. Keep the source of every row | a reviewer can jump to the line on the page |
| 4. Reconcile against the running balance | finds the exact row where something is missing or has the wrong sign |
1. The shape¶
from typing import Optional
from pydantic import BaseModel, Field
class Transaction(BaseModel):
date: str = Field(description="as printed")
description: str
amount: float = Field(description="negative for money out, positive for money in")
balance: Optional[float] = Field(description="running balance printed on this row, if any")
class Statement(BaseModel):
bank: Optional[str]
account_number_last4: Optional[str]
period_start: Optional[str]
period_end: Optional[str]
opening_balance: Optional[float]
closing_balance: Optional[float]
transactions: list[Transaction]
State the sign rule in the schema. Statements print debits and credits in separate columns, and "which column was it" is the most common mistake after a dropped row.
2 and 3. Read it in parts, with sources¶
In the Claude app you can upload the PDF and paste the schema; that is fine for a two-page statement you will read yourself. For anything long, or anything you will save, call it from code. ReadAnyDoc (open source, Apache-2.0) runs Claude page by page and merges the lists:
import readanydoc
out = readanydoc.extract("statement.pdf", schema=Statement, array_extract=True) # PDF, scan or photo
statement = out.data.model_dump() # your JSON
print(len(statement["transactions"]), "transactions")
print(out.citations["transactions[0].amount"]) # the words and the box on the page
print(out.warnings) # e.g. a part that returned fewer rows than its table has
array_extract=True splits the document into parts, compares each part's rows with the row count of the parsed
tables, and reads a short part again. While you are still shaping the schema, add pages=[1, 2] to keep the cost
down.
4. Reconcile: the statement checks itself¶
Opening balance plus every transaction must equal the closing balance, and each printed running balance must follow from the row before it. When it does not, the second rule tells you where.
def reconcile(st, cents=0.01):
"""Problems found by the statement's own arithmetic. Empty list = safe to save."""
problems = []
tx = st["transactions"]
total = st["opening_balance"] + sum(t["amount"] for t in tx)
if abs(total - st["closing_balance"]) > cents:
problems.append(f"transactions give {total:.2f}, closing balance says {st['closing_balance']:.2f} "
f"(off by {st['closing_balance'] - total:.2f})")
prev = st["opening_balance"]
for i, t in enumerate(tx):
if t.get("balance") is None:
prev = prev + t["amount"]
continue
if abs(prev + t["amount"] - t["balance"]) > cents:
problems.append(f"row {i} ({t['date']} {t['description'][:30]}): balance jumps by "
f"{t['balance'] - prev:.2f} but the amount is {t['amount']:.2f}; "
"a row is missing just before it, or the sign is wrong")
prev = t["balance"]
return problems
for problem in reconcile(statement):
print(problem)
With one row (a rent payment of 1,800.00) removed from a four-row example, it prints:
transactions give 3204.50, closing balance says 1404.50 (off by -1800.00)
row 1 (09 Nov Groceries): balance jumps by -1895.50 but the amount is -95.50; a row is missing just before it, or the sign is wrong
The "off by" figure is the missing amount, and the row number is where to look on the page. Save automatically only
when reconcile returns nothing and out.warnings is empty; send the rest to a person with the citation
highlighted (how to show the source on the page).
What this does not solve¶
- Statements with no running balance. Only the opening-plus-transactions check applies; it tells you something is missing, not where.
- Speed. ReadAnyDoc takes 20-50 seconds a page. A 40-page statement is a background job, not a page load.
- Privacy. Page images go to the model provider you choose. If statements may not leave your network, point it at a vision model you host.
- We have not benchmarked bank statements specifically. The figures above are from long financial reports; on 20 invoices the same engine found 99.8% of values.
Questions¶
Can Claude read a bank statement PDF directly? Yes. Short statements work well in one call. Long ones are where rows go missing, without any error.
How do I know no transaction was skipped? Reconcile. If the balances add up row by row, a missing or wrong amount would have to be cancelled out exactly by another error, which is rare enough to save on.
Does it work on scanned or photographed statements?
Yes: the page is read as an image. Faint scans produce more low confidence rows; the reconciliation still applies.
CSV instead of JSON?
pandas.DataFrame(statement["transactions"]).to_csv("statement.csv", index=False).