Book a 30-min callBook a call

Extracting structured data from documents with LLMs: OCR, layout, schemas and validation

How LLM document extraction works: PDF text layers, OCR and layout, vision models on page images, JSON Schemas, field validation, review queues and evals.

A page with text lines and a small table feeding a card of field rows, each with a tick except one flagged row that drops into a review tray.
Written by
BYD Tech
Published
Topic
Deep dives
Reading time
15 min read

Questions people ask

Do I still need OCR if a model can read page images?

Not always. Vision-capable models read page images directly, and the OpenAI and Anthropic APIs both send PDF pages to the model as text and images. OCR is still useful at high volume, where it is faster and uses fewer tokens, for traceability down to word boxes, and as a second reading to compare against when the two disagree.

How accurate is LLM document extraction?

It depends on the documents, the fields and the checks, so measure it on your own labeled set rather than trusting a general figure. Clean born-digital files with a few well-described fields do far better than poor scans of dense tables. Report precision and recall per field, and track how often reviewers change each one.

Should the model return a confidence score for every field?

You can ask, but a number the model writes about itself is a weak signal. Rely first on validation results, agreement between two passes, and whether the value can be found in the page text, and use token log-probabilities where the API provides them.

How do I extract a table that runs over several pages?

Extract each page as rows against the same schema, repeat the table's header in the prompt for every page, keep the page number on every row, and merge in code. Then check that line numbers are continuous and that the rows add up to any totals printed on the document.

Can scanned documents with personal data go to an LLM provider?

Often yes, but it is processing of personal data, so it needs a legal basis, provider terms you have checked for retention, training use and region, and minimization of what you send. Check the rules that apply where you and the people in the documents are.

Building something like this?