Document processing looks solved until you meet the real corpus: rotated scans, two-column layouts, handwritten annotations, tables that span pages, and the one supplier who exports everything as a photo of a printout. A pipeline that only works on clean digital PDFs is a demo. Production means handling the long tail without a human touching every page.
Layout comes before language
Running a language model over raw OCR text throws away the structure that made the document meaningful. Preserve layout first — detect columns, tables and reading order — so a total sits with its label and a table row stays a row. For scanned inputs, the boring preprocessing of deskewing, denoising and resolution normalisation moves accuracy more than swapping the OCR engine.
- Detect and correct orientation and skew before OCR runs.
- Preserve reading order and table structure, not just a flat text dump.
- Keep bounding boxes so every extracted field can be traced to a location on the page.
Extract to a schema and validate hard
Ask the model for structured output against an explicit schema — typed fields, required keys, expected formats — rather than free text you parse later. Then validate what comes back: dates that parse, totals that equal the sum of line items, invoice numbers that match a pattern. Deterministic checks catch the confident-but-wrong extractions that no amount of prompting fully eliminates.
Confidence routing keeps humans on the hard cases
Not every page deserves the same trust. Score each extraction and route high-confidence results straight through while queuing the uncertain ones for a reviewer. The queue is not overhead — it is your labelled data for improving the pipeline, and it keeps expensive human attention on the documents that actually need it.
- Set a confidence threshold per field, tuned to the cost of a wrong value.
- Send low-confidence and failed-validation documents to a review queue.
- Feed corrected extractions back as evaluation cases and prompt examples.