In this article
Extracting structured data from documents with OCR and a language model looks simple in a demonstration. Upload a clean PDF, watch the fields appear, done. Then real users arrive. They upload photos of documents taken at an angle, in poor light, with a thumb in the corner. Two languages on one page. Handwriting in the margins. Page two before page one. The pipeline that scored 98% in the meeting falls apart, and someone asks why the AI project is not working.
We built a production system that turns exactly this kind of input, photographed pages of study material uploaded by ordinary users, into structured, validated question banks. It is documented in our AI EdTech case study. Building it taught us where the difference between a demo and a product lies, and it is almost all in the pipeline around the model.
Reject bad input early
The cheapest place to fix a bad document is before processing it. Our intake stage checks image quality, including resolution, blur and skew, and tells the user immediately when a photo will not survive OCR, while they are still holding the document and can retake the shot. One clear message such as "this photo is too blurry, please try again" removes a whole category of downstream failures and support tickets.
What we deliberately avoid is accepting everything silently and letting failures surface three stages later, when the user can no longer do anything about them.
OCR is a commodity; the cleanup is not
Modern OCR engines are good and largely interchangeable for most workloads. The engineering is in what happens next: stitching text across page boundaries, preserving reading order in multi-column layouts, keeping tables intact, and tagging which language each block is in. This cleanup layer sets the quality ceiling for everything downstream. Skimp here and no amount of prompt engineering will recover the loss.
The model structures, the schema judges
We hand the cleaned text to a language model with one job: produce structured output that matches a strict schema. Not "summarise this", but extract these fields, in this format, within these constraints.
Then we validate everything the model returns, which is the step demonstrations skip. Are required fields present? Are values within legal ranges? Are cross-references consistent? In the EdTech system, every generated question is checked for structural completeness before a user sees it. A question with no correct answer marked, or four identical options, is caught by validation code rather than by a paying customer.
The model is not the quality gate. The schema and the validators are.
Route by confidence
Every document leaves the pipeline in one of three lanes. A clean pass is validated and done. A flagged pass is usable, but something was uncertain, so it is queued for optional review. A failure has a clear reason logged and the user is told. The proportions between the lanes are the real health metric of the system, and we watch them week by week. When flagged passes creep up, something has changed: a new document format, a new user population, an OCR regression. You want to know before the failure lane tells you.
This is also where cost is controlled. Inexpensive models handle the easy majority, and only the hard documents reach the expensive model. Cost per document is an architecture decision rather than a billing surprise.
Where this pattern applies
Study material was our case, but the shape of the pipeline is general: invoices into accounting fields, delivery notes into inventory records, contracts into clause summaries, inspection forms into compliance databases. If your team retypes information that is already written on paper, this architecture removes that work, with people reviewing the uncertain cases instead of processing the whole pile.
This is the core of what we offer as AI automation services, and it connects to our broader AI software development work. If you have a document-heavy process and a folder of difficult scans, send us one painful example and we will tell you what a pipeline can and cannot do with it.