> ## Documentation Index
> Fetch the complete documentation index at: https://docs.helix-db.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How do you extract structured data from documents?

> Turn contracts, notes, and reports into typed records and facts by defining a target shape, extracting with a model, verifying each claim against its quote, and reviewing the rest.

Concept

To extract structured data from documents, define the shape you want, such as a
contract's customer, start date, and renewal terms, then have a model read each document
and fill that shape, keeping the quote behind every value. Check each extracted fact
against its quote, link the names it mentions to records you already hold, and send what
the checks cannot settle to a person. Think of it as turning a pile of paperwork into rows
in a spreadsheet, with a footnote on every cell.

> [card] Learning objectives
>
> After reading this article you will be able to:
>
> * Explain what document extraction produces: entities, facts, and their quotes
> * Describe why a target shape, such as an ontology, comes first
> * Outline an extraction pipeline from parsing to review
> * Describe how to verify extracted facts and control cost

## What does document extraction produce?

It produces three things: the entities a document names, the facts it states about
them, and the evidence for each fact. A sentence such as "Northwind signed the services
agreement on March 1, 2026" yields a `Customer` named Northwind, a `Contract`, a `SIGNED`
link between them with a `signedOn` date, and the quote that states it.

| Output | What it is | Example |
| - | - | - |
| Entity mention | A name the document uses for a thing | "Northwind", "the Client" |
| Property value | A typed value about an entity | `signedOn = 2026-03-01` |
| Relationship | A typed link between two entities | `Customer -[SIGNED]-> Contract` |
| Evidence | The exact quote, and where it is | Page 2, "signed the services agreement on March 1, 2026" |
| Confidence | How sure the check was | A verifier's score of 0.94 |

Together they become part of a
[knowledge graph](https://docs.helix-db.com/learn/graph-databases/what-is-a-knowledge-graph.md): structured facts
that can be queried, joined with tables, and cited.

## Why do you need a target shape first?

Because a model asked to "pull out everything important" returns something different
for every document. A fixed shape, the types, properties, and links you want, makes
every document's output comparable and lets you reject output that does not fit.

That shape is usually an [ontology](https://docs.helix-db.com/learn/ontologies/what-is-an-ontology.md). It also
says which documents may fill which types: a contract can name a customer and a renewal
date, while call notes can name a product and a complaint. Narrow targets extract more
accurately than broad ones, because the model has fewer places to put a wrong answer.

> [card] [Try Helix Foundry](https://docs.helix-db.com/foundry/start-here/quickstart.md)
>
> Read your documents into the same HelixDB graph as your tables, with the quote behind every fact.

## How does an extraction pipeline work?

Parse the document into text, extract candidate facts in the target shape, verify each
one against its quote, link names to known records, and store the result with its
evidence.

**1. Parse**

Turn PDFs, Markdown, and text into clean text with its structure: sections, pages,
and tables. Table files such as CSV are better loaded as tables than read as prose.

**2. Extract**

Give a language model the target shape and a section of the document, and ask for
entities, properties, and relationships in a fixed format, each with the quote it
came from. Reject output that does not validate against the shape.

**3. Verify**

Check that each quote really appears in the document and really states the fact.
A second model call or rule can score each claim, so weak claims are held rather
than stored as settled.

**4. Resolve**

Link each name to an existing record, so "the Client" in a contract becomes the
customer already in your billing table. This is
[entity resolution](https://docs.helix-db.com/learn/ontologies/what-is-entity-resolution.md), and it decides
whether the new facts join the right entity.

**5. Store with provenance**

Write the facts with their quotes, document, and confidence, the
[provenance](https://docs.helix-db.com/learn/ontologies/what-is-data-provenance.md) that lets anyone check
them later.

Extraction is a different job from chunking for
[retrieval-augmented generation (RAG)](https://docs.helix-db.com/learn/ai-memory/what-is-rag.md). RAG keeps passages
of text and finds them with [vector search](https://docs.helix-db.com/learn/vector-search/what-is-vector-search.md)
at question time; extraction turns the text into facts ahead of time, so questions such
as "which contracts renew next quarter?" become a query, not a search.

## How do you know extracted facts are right?

You check them in layers: validate the shape, verify each quote, compare with your
tables, and have a person look at what the checks cannot settle.

* **Quote verification.** A fact whose quote is missing or does not say what the fact
  claims is dropped or held.
* **Cross-checks with tables.** When a document disagrees with a system of record, such
  as a different renewal date than billing holds, flag the conflict instead of picking
  one silently.
* **Unresolved names.** A name that matches no record, or several, is held for a person
  rather than creating a duplicate entity.
* **Sampling.** Reviewing a random sample of accepted claims measures how often the
  pipeline is right at each confidence score, which tells you where to set thresholds.

## How do you control the cost of extraction?

Model calls are the main cost, so read each document once and only re-read what changed.

* **Cache by extraction inputs.** Key results by document content, model, target shape,
  and extraction instructions, so unchanged inputs can reuse an earlier result instead
  of paying for a new model call.
* **Extract incrementally.** When a document is replaced or a new one arrives, read only
  that document. When one is deleted, its provenance says which facts to remove.
* **Route documents.** Only read a document for the types it can fill, and skip sets no
  question needs.
* **Cap spend.** Set a budget per run and per month, and let a run stop partway rather
  than overspend.

## How does Helix Foundry extract data from documents?

[Helix Foundry](https://docs.helix-db.com/foundry/start-here/introduction.md) reads documents into the same HelixDB
graph as a company's tables:

* **Routes.** A [generation](https://docs.helix-db.com/foundry/ontologies/generate-and-version.md) reads up to five
  of the newest documents in each set it picks and drafts routes: what each set's
  documents may fill, such as a contract's signing date and the customer it was signed
  with.
* **Names, facts, and quotes.** A [load](https://docs.helix-db.com/foundry/ontologies/load-data.md) reads every text
  document and PDF in the version's sets for its sections, the names it mentions, and
  the facts it states, each with the quote it came from. AI models find the names and
  facts and check them. Table files are loaded as tables.
* **Review instead of guessing.** A name the database doesn't hold, an ambiguous name, a
  quote that couldn't be verified, or a fact that conflicts with the tables waits on the
  [Review](https://docs.helix-db.com/foundry/ontologies/review.md) page instead of becoming a record. About one card
  in ten there is a random check that measures how often claims at each score are
  right.
* **Paying once.** Reading the same text with the same models again costs nothing, and
  a document added to a set the current load reads is read as it arrives. See
  [Documents](https://docs.helix-db.com/foundry/data/documents.md).

## Frequently asked questions

### Is document extraction the same as OCR?

No. OCR (optical character recognition) turns an image of a page into text. Extraction
starts from text and turns it into typed facts. Scanned documents need OCR first.

### Can a language model extract data reliably?

Reliably enough when the target shape is narrow, every fact carries its quote, and the
quotes are checked. Without those, models can invent plausible values that no sentence
states.

### Should you extract or just use RAG?

Use [RAG](https://docs.helix-db.com/learn/ai-memory/what-is-rag.md) for open-ended questions over prose, and
extraction for facts you will filter, count, or join with tables. Many applications do
both, and a [hybrid search](https://docs.helix-db.com/learn/full-text-search/hybrid-search.md) over the original
text is still useful for finding passages.

### How do you handle documents that disagree?

Keep both claims with their provenance, prefer a system of record or the newer dated
document by a fixed rule, and send what no rule settles to a person. See
[what happens when sources disagree](https://docs.helix-db.com/learn/ontologies/what-is-data-provenance.md#what-happens-when-sources-disagree).

## Related topics

> [card] [What is an ontology?](https://docs.helix-db.com/learn/ontologies/what-is-an-ontology.md)
>
> The target shape extraction fills.

> [card] [What is entity resolution?](https://docs.helix-db.com/learn/ontologies/what-is-entity-resolution.md)
>
> Linking extracted names to the records you already hold.

> [card] [What is data provenance?](https://docs.helix-db.com/learn/ontologies/what-is-data-provenance.md)
>
> Keeping the quote behind every extracted fact.

> [card] [What is a knowledge graph?](https://docs.helix-db.com/learn/graph-databases/what-is-a-knowledge-graph.md)
>
> Where extracted facts end up, connected to everything else.

> [card] [What is RAG?](https://docs.helix-db.com/learn/ai-memory/what-is-rag.md)
>
> Retrieving passages at question time instead of extracting ahead.

> [card] [What is GraphRAG?](https://docs.helix-db.com/learn/ai-memory/what-is-graphrag.md)
>
> Answering questions by following extracted facts.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.