Custom OCR pipelines: from reading a document to trusting the data

OCR (optical character recognition) is the technology that turns an image of text into text a computer can work with. It has been around for decades, and any phone can do it today. Which makes it all the more surprising that so many companies still type invoices and delivery notes in by hand.

The reason is simple: reading the characters isn’t the hard part. The hard part is knowing what each number means, where it belongs, and whether you can trust it.

Why generic OCR isn’t enough

Generic OCR gives you the text on the page. But a real invoice isn’t a clean page. It’s a supplier’s PDF, a crooked phone photo, a scan with a coffee stain, or a delivery note signed in biro right across the totals.

And even when the text comes out perfectly, there are questions OCR doesn’t answer:

  • Which of the three date-like numbers is the invoice date?
  • Is that tax ID the supplier’s or the customer’s?
  • Do the net amount and the VAT add up to the total at the bottom?
  • Does this supplier always invoice at this VAT rate, or is today different?

Every company has its own suppliers, formats and exceptions. That’s why a system built for everything tends to fall short on the specifics.

What an OCR pipeline is

A pipeline is a chain of steps, each with one clear job, where the output of one becomes the input of the next. For documents, ours usually has four:

  1. Reading. The image is prepared (straightened, cropped, contrast improved) and the text is extracted along with its position on the page.
  2. Field extraction. Each piece of data you care about is identified: supplier, tax ID, date, invoice number, net amount, VAT rate, total, line items. Only the fields your process needs, in the format your system expects.
  3. Cross-validation. Every value is checked in more than one way before it’s accepted.
  4. Human review of exceptions. Anything that fails the checks doesn’t slip through quietly: it’s flagged and a person reviews it.

The third step is the one that makes the difference.

Checking in more than one way

An extracted value is a proposal, not a fact. To turn it into reliable data, we check it against other sources and against rules that don’t depend on the same model that read it. For example:

  • Arithmetic. Line items must add up to the net amount; the net amount times the VAT rate must give the tax; and the two together must give the total.
  • Format. Many tax IDs, such as the Spanish NIF, carry a check character that can be computed. If it doesn’t match, the ID was misread.
  • History. If a supplier has invoiced at one VAT rate for two years and a different one shows up today, it deserves a look.
  • Double reading. The same field can be obtained by two different methods. If they agree, confidence goes up. If not, it’s escalated.

The rule is simple: if the checks don’t agree, the value doesn’t go in. We’d rather send a question to a person than let an error through. That way the team stops typing everything and only reviews what genuinely needs a human eye.

A real case: an accounting firm

At an accounting firm that keeps the books for dozens of companies, invoices arrived every month as PDFs and photos, by email and in shared folders. Every value was typed in by hand before anyone could work with it.

We installed a system in the firm’s own office that reads each invoice, extracts the fields and prepares part of the journal entry using the templates the firm already worked with. It was adapted to their spreadsheets, not the other way round. Every value is checked in more than one way; if the checks disagree, it’s flagged and a person reviews it.

The team went from typing everything to reviewing only the exceptions. And the documents never leave the firm’s server: no usage fees, and no client data travelling to outside services.

The same idea on a production line

Computer vision isn’t only about reading paperwork. In manufacturing, a camera over the line can inspect every part and catch defects (a crack, a dent, an incomplete weld, a misplaced label) before the part ships.

The approach is the same as with invoices. The model is trained on images of your parts and your defects, not on a generic catalogue. Every detection is stored with the image that justifies it, so whoever reviews it sees exactly what the system saw. And anything uncertain is set aside for a person rather than decided blindly.

If your company has documents someone types in every week, or an inspection that relies on nobody getting distracted, write to us at info@liberionlabs.com. We’ll start by looking at how you work today.