How To · DomainIntermediate

How to Extract Structured Data from Documents with LLMs

How to extract structured data from PDFs with AI: OCR, layout, JSON schemas, bounding-box citations, and a human review queue for invoices and contracts (2026).

OCR + layoutJSON SchemaVision LLMBox citationsHITL review queue15 min · 6 steps · Updated 2026-08-25
The short answer

To extract structured data from documents with LLMs, run OCR and layout on each page, constrain the model to a JSON Schema, require a bounding-box citation per field, and send low-confidence or high-value records to a human review queue. Document AI extraction is a pipeline with evals, not a single “read this PDF” prompt.

What you’ll build

  • A pipeline that turns PDFs and scans into schema-valid JSON with field-level confidence
  • Citations from each extracted value back to a page and bounding box
  • A human review queue gated on confidence, schema fails, or high-value amounts
  • Field-level precision/recall on a frozen golden set, plus a CI gate
  • Idempotent re-processing when the schema or model pin changes

Before you start

  • 01A sample of 50+ real documents (invoices, forms, contracts) with ground-truth fields
  • 02A JSON Schema for the record you need, with types, enums, and required fields
  • 03OCR/layout or native-text extraction for PDFs, plus page images for scans
  • 04A review UI that can show the source page and bounding box next to each field
  • 05Storage for document bytes, model versions, and reviewer decisions the client owns

Key takeaways

  • 01

    Layout-aware OCR plus page images beats a raw text dump on invoices, forms, and scanned contracts.

  • 02

    JSON Schema (with constrained decoding or repair) is the contract between the model and downstream systems.

  • 03

    Every field should point at a page and box; that citation is how reviewers and auditors trust the number.

  • 04

    Human review on confidence, schema failure, and amount thresholds is the production control — not a nicer prompt.

  • 05

    Score field-level precision/recall on a golden set of real documents; CI should fail when a pin drops a critical field.

01

What document AI extraction is

Extracting data from PDFs with AI means turning messy pages into records a system can post: vendor, dates, line items, totals, clauses. Classic OCR plus templates breaks when a new vendor layout appears. LLMs (text, vision, or both) generalize across layouts if you give them structure: schema, layout tokens, and a rule for what to do when a field is missing.

The unit of work is one document family and one schema. “Ingest the shared drive” is not a pipeline. Invoice OCR LLM projects fail when they try to also do contracts in the same prompt. Split the traffic.

02

OCR, layout, and when to send images

Digital PDFs often already contain text; use it and still keep coordinates. Scans need OCR. Layout models mark tables, headers, and key-value pairs so line items stay rows. Reading order errors are a top source of swapped fields (ship-to vs bill-to).

Vision LLMs help on stamps, handwriting, and layouts OCR mangles. They cost more and still need a schema. A hybrid that OCRs first and sends page images only when native text is thin is usually the production default. Measure both paths on the same gold docs.

03

Schemas, constrained decoding, and tables

The schema is the product. Use JSON Schema with required fields, date formats, currency codes, and decimal types. Constrained decoding (grammar/JSON mode) reduces repair. Still validate: models emit extra keys and stringified numbers. A repair loop that re-asks only invalid fields is cheaper than regenerating the whole document.

Line items belong in arrays with their own citations. Totals should be checked against the sum of lines within a tolerance; mismatches go to review even if the model was confident. That single arithmetic guard catches a class of fluent errors evals love to miss.

04

Bounding-box citations and the review queue

A field without a box is an unverified claim. Store page, coordinates, and the snippet. The UI highlights the box when the reviewer focuses a field. Query-time ACLs still apply: reviewers only see documents their role allows, same as any other enterprise retrieval.

Route on confidence, missing citations, schema failure, new vendors, and amount thresholds. Measure straight-through processing (STP) rate and reviewer time per doc. Human edits become training and gold; they should not vanish into a spreadsheet. Shadow mode can run a new model pin next to production and compare field diffs before you change STP gates.

05

Field-level evals that match the ERP

Score per field: precision, recall, exact match after normalization (dates, money, IBAN spacing). Score citation IoU or “box contains value.” Weight fields by risk: IBAN errors are not the same as a missing PO line note. Keep a frozen set of real vendor docs; synthetic invoices under-test stamps and skew.

CI runs on OCR/layout/LLM pin changes. A four-week implementation can freeze the schema and gold in week 1, pipeline in week 2, review UI and shadow in week 3, and handover of datasets, evals, and runbooks in week 4. The client owns the labels and the model pins. 98.7% QA pass rate on delivery work does not replace your field-level gold — it is how the implementation itself is checked.

  • One document family, one JSON Schema, labeled gold docs
  • Layout OCR + optional page images, split by page/region
  • Schema-valid JSON with page/box citations per field
  • HITL on confidence and money; field-level CI on pins
06

When not to use an LLM for extraction

Fixed-form, high-volume, identical templates may still be cheaper with a classic template or a small specialist model. Handwriting-only archives may need a dedicated HTR stack. If you cannot show a reviewer the source box, do not auto-post payments.

Do not send documents that must not leave the perimeter to a public vision API. Deploy the extractor in the client VPC, same rule as any other private LLM path.

Step-by-step build

  1. 1

    Define the schema and the document family

    Write a JSON Schema for one document type (invoice, claim, KYC form). List required fields, types, enums, and which fields are money or identity. Do not mix families in one schema. Collect 50+ labeled examples spanning vendors, languages, and scan quality.

  2. 2

    Extract text, layout, and page images

    For digital PDFs, pull native text and character boxes. For scans, run OCR. Keep layout: blocks, tables, key-value regions. Store page images at a resolution the vision model can read. Split long documents by page or by detected sections.

  3. 3

    Call the LLM with schema constraints

    Pass the schema, the page content (text + optional image), and instructions to emit only schema-valid JSON. Use constrained decoding or a validate-and-repair loop. For tables, extract line items as arrays rather than stuffing them into a blob.

  4. 4

    Attach bounding-box citations

    For each field, record page number and box coordinates of the supporting span. If the model cannot locate a box, mark the field uncited and drop confidence. Reviewers click the box; they should not hunt the page.

  5. 5

    Route to a human review queue

    Auto-accept only when schema validates, citations exist, and confidence and amount thresholds pass. Otherwise queue with the image, boxes, and model JSON. Capture reviewer edits as new gold. Never write to finance systems from unreviewed low-confidence records.

  6. 6

    Evaluate and reprocess on pin changes

    Score field-level precision/recall, citation accuracy, and straight-through rate on the golden set. Pin OCR, layout, and LLM versions. When any pin changes, re-run the set in CI and reprocess production docs that failed or sat in the queue.

Common pitfalls

The mistakes that show up in real deployments — each one costs a week if you learn it the hard way.

Sending 40-page PDFs as one blob

You will lose tables, blow the context window, and mix line items from page 2 with totals from page 7. Split by page or by layout region, then merge with the schema.

OCR without layout

Reading order on invoices is not top-to-bottom English prose. Keep bounding boxes, table cells, and key-value pairs from a layout model, not only a text dump.

No schema, just “extract everything”

Unconstrained JSON cannot be validated or compared to gold. Define the record first. Constrained decoding or a repair loop against JSON Schema is cheaper than arguing with free-form output.

Auto-posting to the ERP on day one

A plausible IBAN that is wrong is a payment incident. Route below-threshold and high-value fields to humans. Measure straight-through rate; do not assume it.

Evaluating only exact string match on amounts

Normalize currency, decimals, and dates before scoring. Also score citation hit (box contains the value). A correct number with no source is not ready for audit.

Frequently asked questions

How do you extract data from a PDF with AI?

Run OCR and layout (or native PDF text with coordinates), send each page or region to an LLM constrained by a JSON Schema, require a bounding-box citation per field, and review low-confidence or high-value records. Evaluate field-level precision/recall on real documents, not on one demo invoice.

Do I need OCR if I use a vision LLM?

Often yes. Native text and layout boxes are cheaper, more precise for citations, and more stable for tables. Use a vision LLM when scans, stamps, or handwriting defeat OCR. Many production pipelines OCR first and add page images only on low-confidence pages.

How do invoice OCR LLM pipelines avoid posting wrong amounts?

Validate JSON Schema, check that totals match line items within a tolerance, require a box citation on money fields, and send above-threshold or low-confidence invoices to a human. Do not connect auto-post to the ERP until straight-through rate and field recall on gold are written down and met.

What is a bounding-box citation in document AI?

It is the page plus coordinates of the pixels or characters that support a field. Reviewers and auditors use it to see where a value came from. An extracted IBAN without a box is an ungrounded claim and should not auto-post, even if the JSON looks valid.

How do you measure document extraction quality?

Use a frozen set of real documents with gold fields. Report per-field precision/recall after normalizing dates and money, citation accuracy, schema-valid rate, and straight-through rate. Gate CI on critical fields (amounts, IDs). Average accuracy across easy and hard fields will hide payment errors.

Want this built for your team?

From architecture review to a deployed, evaluated system your engineers own — we ship it with you.

FAQ

Working with us

How soon can this build work start?

Typically within a week or two of a scope being agreed. The first delivery is deliberately a small batch so you can check the output against your expectations before volume ramps.

What do you need from our team?

One process owner who knows the workflow, one engineer with access to the systems involved, and a weekly 45-minute review. No standing committee, and no requirement for an ML specialist on your side.

Who owns the output and the data?

You do. Datasets, labels, weights, evaluation suites and runbooks are yours and are handed over at the end. Your data trains your models only, with zero-retention provider settings by default.

Can you scale volume up quickly if we need it?

Yes, and the quality bar holds because the rubric and gold set are already agreed by that point. Ramping is a staffing question, not a re-scoping one, so it usually takes days rather than a new engagement.

We already have a vendor for this. Why switch?

Often you should not. The cases where teams move to us are when they cannot get a quality number out of their current vendor, or when the work is delivered as an opaque batch with no trace of how disagreements were resolved.

What happens after the engagement ends?

We stay on-call for 30 days at no extra cost, then move to an optional support retainer. Most teams also keep a quarterly evaluation review with us to catch drift early.

Copyright © 2026
ReinforcedX, Inc.
All rights reserved