Vaibhav Nakrani
← WorkLog 05 / 11Documents

Freight-invoice reconciliation

A cleanup contractor suspected it was being billed twice for some truckloads. The proof was somewhere in 25 GB of scanned paperwork.

Client
Terrabase, for one of its customers
Role
ML engineer, freelance
When
August – October 2025
Stack
jina-clip-v2, Gemini 2.5 Pro, Pydantic, PyMuPDF, Docker
$363Kin cancelled invoices still being billed
47K+scanned pages sorted
5,625extracted amounts checked against the client's books. All matched
0classifiers trained
How it works

The client had a pile of scanned paperwork: big files where invoices, shipping forms and other pages were all mixed up. The question was whether some truckloads had been paid for twice.

The system does three things. It picks out the invoices and shipping forms by comparing every page with a few examples of each. It reads the picked pages into rows of a table: invoice number, load number, amount and so on. Then it does the bookkeeping: for every refund, find the charge it cancels, and see whether that charge is still on the books. Every amount it read was compared with the client's own records before anyone relied on it.

Problems and fixes

Sorting and reading at once. I first asked one model to say what a page was and read it in the same step. It mixed the page types up badly. Splitting the work fixed it: one step sorts, the other reads, and the reader gets instructions written for that kind of page.

Pages that look alike. Order sheets and tickets share a layout with invoices, and the shipping forms were blurrier scans than the rest. One cut-off did not suit every page type, so each got its own, and two more rounds removed the near-misses.

Crooked scans. When a page was scanned at an angle, the end of the invoice number was often lost while the amount was still right. If the amount agreed with the client's records and the number nearly did, the number was corrected and the page marked for a person to check.

One load, several spellings. The same load number showed up with extra zeros in front, a letter at the end or an added digit, depending on which system printed it. Comparing only the digits matched most of them. The rest went on a short list for a person.

Trusting the invoice codes. Invoice numbers end in a code that is meant to say original, credit or correction. My first rule believed those codes, and the totals came out absurd. The codes were not used the same way every time, so I ignored them and matched each refund to a charge of the same size on the same load.

From pages to invoices
47,579scanned pages, in mixed bundles of up to 1,958 pages
6,777invoices found and read
5,625amounts checked against the books. All 5,625 matched
68orders where the carrier issued a corrected invoice
62 · $363Kcancelled invoices still on the books
Walkthrough

The four-minute version, in my own words.

Working on something like this? Message me on LinkedIn → or email nakranivaibhav14@gmail.com