Documents as Data: Building LLM Extraction Pipelines

By Arshad Ansari

An LLM can read a contract and return a table. Treat that table as a set of claims, not as data. Each claim needs a source, a check and an owner before anything downstream uses it.

This essay is part of a series on meaning in data systems. Earlier pieces covered entity resolution and semantic integration. This one covers the step before both: getting claims out of documents.

Documents are the largest source nobody models

Most companies hold their most important facts in files. Contracts hold terms and dates. Reports hold figures. Emails and chat messages hold decisions. None of this sits in a table, so none of it reaches the warehouse.

An LLM makes it cheap to read these files. That is the easy part. The hard part is deciding what you will trust, and what happens when the model is wrong.

Extract claims, not values

Do not ask the model for "the renewal date". Ask for a claim with its evidence.

A useful claim record has these fields:

  • Subject. What the claim is about, such as a contract or a supplier.
  • Field and value. The renewal date, and the date as the model read it.
  • Source reference. The document ID, the page and the exact quoted passage.
  • Extractor version. The model and the prompt that produced it.
  • Status. Proposed, validated, approved, rejected or corrected.

The quoted passage matters most. It lets a reviewer check a claim in seconds, and it lets a program check that the passage really appears in the document. A claim whose quote is not in the file is a fabrication. Reject it without asking a person.

Validate in layers

Put cheap, exact checks first. Put people last.

  1. Shape. The output matches the schema. Dates parse. Amounts are numbers. Required fields exist.
  2. Grounding. The quoted passage appears in the source text, and the value can be derived from it.
  3. Rules. The claim fits what you already know. An end date comes after a start date. A currency is one you trade in. A party name matches a known entity.
  4. Agreement. For high-value fields, run the extraction twice with different prompts or models. If they disagree, flag the claim.
  5. Review. A person sees what is left: the flagged claims and the consequential ones.

Each layer removes work from the next. The layers also give you a reason for every rejection, which you will need when you tune the pipeline.

Keep the source and the claim apart

Store the original document, the extracted text and the claims as separate things. Never overwrite a claim with a fix. Add a new claim that supersedes the old one, and keep both.

This gives you two things. You can replay the pipeline when the model or the prompt changes, and compare old and new claims side by side. And you can answer the question an auditor will ask: where did this number come from, and who approved it?

Entity resolution comes after this step. A claim that names a supplier still has to be matched to the right supplier record. Keep that match as its own claim too.

Build the correction loop on day one

People will fix claims. If the fix only changes a value in a table, you have lost the most useful signal in the system.

Record each correction as data: the original claim, the corrected value, the reviewer and the reason. Then use it three ways:

  • Add the corrected cases to a test set, so the next prompt change is measured against real mistakes.
  • Look for patterns. If one document layout causes most corrections, fix that layout once.
  • Tighten the rules. A correction that repeats becomes a validation check.

Without this loop, the pipeline makes the same mistake every week and nobody learns it.

Decide which claims need a human

Not every claim needs a person. A claim that feeds a dashboard label is low risk. A claim that moves money, sends a notice or changes a contract record is not.

I draw the line by consequence, not by model confidence. Model confidence scores are poor guides to correctness. Instead, list the actions downstream of each field. If an action is hard to undo, the claim behind it waits for approval. The same rule applies to any AI workflow I build: consequential actions wait for a person.

What to expect when it runs

Things that go wrong in practice:

  • Scans and tables. Text extraction from poor scans and complex tables fails quietly. Check the text before you check the claim.
  • Long documents. A fact on page 40 can contradict a fact on page 3. Extract per section, then reconcile.
  • Silent drift. A model update changes outputs without any code change. Pin versions and re-run your test set before you switch.
  • Missing fields. A model asked for a field will often invent one. Allow "not stated" as a valid answer and reward it.

I will not give you an accuracy figure here. It depends on your documents, and a number from someone else's files tells you nothing about yours. Measure it on a sample of your own, with a reviewer, before you promise anything to anyone.

Who should not build this

If you need a few values from a few files, read them yourself. A pipeline costs real effort to build and to keep. It pays off when the same kind of document arrives again and again, and when someone downstream depends on the answer.

Check your own setup first

If you already have an AI pilot that reads documents and has not reached daily use, start with the AI Workflow Teardown. It is free and you can run it yourself. If the problem is where the extracted claims will land, the Data Platform Teardown covers that side.

Common questions

Can an LLM extract structured data from documents reliably?
It can, if you treat its output as a claim, not a fact. Check each claim against a schema and rules, keep a reference to the source text, and route doubtful claims to a person.
What should I store besides the extracted value?
The source document, the exact passage, the model and prompt version, the validation result and who approved it.
Who should not build this?
Anyone who needs a number from a document once, by hand. A pipeline pays off only when the same kind of document keeps arriving.

Get new posts by email

Data engineering notes like this one — what breaks and what it costs, in production.

What breaks and what it costs — pipelines, warehouse bills, and the failures that only show up in production. A few a month, never padded to hit a schedule. No sequence, no pitch deck. Reply 'stop' once and you're off — it reaches me, not a queue.

Want the whole playbook?

If this was useful, the long version is my book. Local-First Analytics — 313 pages, runnable code for every chapter — is the full build: DuckDB, Parquet and Arrow, from install to production. On Amazon, and chapter 1 is free to read here.

Not ready to buy? Read chapter 1 free — the whole chapter, no email required.

Rather talk it through? Book a free 30-minute call. No slot that suits your time zone? Email info@hikmahtech.in.