Writing · AI · OCR · Claude
The model reads, the code decides: AI document reading that can’t put a wrong number in the books
By Saksham Srivastava5 min read

Papers arrive as photos: invoices, weighbridge slips, payment slips. Reading them with an AI model is the easy part now. The hard part is deciding how much of what it read to believe, because a misread “8” becomes a wrong bill, and wrong bills are exactly what this backend is built to refuse.
So the rule is the same as everywhere else in it: the model is allowed to read. Only code is allowed to decide.
1. The model copies; code converts
The model is asked to copy what is printed, exactly as written, into one JSON object. It is never asked to add anything up, convert a unit or reformat a number. Code does that: Indian comma grouping (1,23,456), weights into quintals, dates into dates. A model that “helpfully” turns 12,345 kg into 123.45 quintals has nowhere to do it.
# what the model returns: copied text, nothing worked out
{"net_weight": "12,345 KG", "date": "25/11/26", "plate": "UP 32 XX 0000"}
# what code makes of it
net = to_quintals(parse_indian_number("12,345"), unit="KG") # 123.45
day = parse_date("25/11/26") # 2026-11-25
plate = normalise_plate("UP 32 XX 0000") # UP32XX00002. Every figure has to agree with something
A reading is only trusted when it agrees with something else, on the paper or in the system:
- an invoice line’s rate is kept only if quantity × rate lands within 1% of the printed amount;
- a receipt whose bill amount is at or above its goods amount is flagged, and never used for automatic matching;
- a delivery date has to fall between the day the order was made and tomorrow, or the page gets a second look;
- if a paper isn’t a cheque, any “amount” read off it is dropped;
- a maker’s copy and an authoriser’s copy of a payment pair up only if the amounts agree within ₹1 and the payee matches.
None of these are clever. They are the checks a careful clerk does without thinking. Writing them down means they happen every time, at three in the afternoon and at the end of the month.
3. A reading fills blanks; it never overrules a person
What the reader finds only fills fields that are still empty. If somebody typed a value, the typed value wins. On the purchase desk, the reader fills the form and a person posts it.
Where weight matters most, goods arriving at the mill, a person confirms the plate and the weight, and the system compares them with the order: within half a quintal, and a plate one character off is accepted only if the weight agrees. Anything else blocks posting.
And no reading ever becomes an accounting entry on its own. Slips feed the picture of what has been paid. The books only move when a person posts.
4. Retries that respect the other side
Reading calls retry three times with growing waits (1.5 s, 4 s, 9 s), honour the provider’s retry-after, and only for errors worth retrying. Each person can make 400 reads per ten minutes. Background reading never holds a database connection while it waits for the model.
What this buys you
- Typing saved where it is safe, and not one step further.
- A misread can’t reach the books: it has to agree with the paper and pass a person first.
- The model can be swapped without touching a single business rule.
Let the model read. Never let it decide.
I’m Saksham Srivastava, a full-stack & AI engineer in Lucknow and co-founder of Sqaron Technologies. Work with me or see what I’ve built.
- AI
- OCR
- Python
- Backend
- Also on DEV
Read nextRefuse, don’t repair: building accounting books that can’t go wrong24 Nov 2026 · 4 min All writing