
This blog is written by AI for SEO
How to Extract an Ontology From Contracts and PDFs
To extract an ontology from documents, decide which question the model has to answer, define the entity types behind it, have an LLM pull facts that each carry the quote they came from, match every fact to an existing customer record, and send disagreements to a person. An ontology here just means a typed map of the things your business cares about (customers, contracts, renewals, owners) and the links between them.
That is the whole method, and you can run it with a spreadsheet and a script. This guide walks through it tool-agnostic first, then shows how Helix Foundry does the same job on its built-in Acme Corp sample, where every value traces back to a table row or a quote in a document.
What it means to extract an ontology from documents
Extracting an ontology from documents means turning prose (a contract clause, a line in call notes, a paragraph in an incident report) into typed entities and links that sit next to the records your database already holds. The output is not a summary. It is a set of facts such as "Acme Corp has a contract that renews on a given date, owned by a given person", each pointing back to the sentence it came from.
Two things separate this from plain document search. First, the facts are typed, so you can ask "which contracts renew this quarter" instead of "find text near the word renew". Second, the facts connect to your existing customer records, so a PDF stops being an orphan file and becomes a property of a customer row you already trust.
If you are still deciding whether you need one at all, Do You Need an Ontology? Five Signs Your Data Needs One covers that, and Ontology vs Knowledge Graph covers the vocabulary.
Without any tool: five steps from contract to connected facts
You can do this by hand or with a short script. The five steps are the same whatever software you use.
1. Write the goal question first. Pick one question the result must answer, for example "Which customers have a renewal in the next 90 days, and who owns each account?" The question decides everything after it. Without one, extraction sprawls into hundreds of entity types nobody queries.
2. Pick a short list of entity types. Work backwards from the question. For the renewal question that is Customer, Contract, Renewal Date, Owner. Add a link for each relationship: a Contract belongs to a Customer, a Customer has an Owner. Five to eight types is plenty to start. Add more once the first set works.
3. Extract with an LLM, and keep the quote. For each document, prompt the model to return facts in your types and, for every fact, the exact sentence it relied on. Reject any fact with no quote. The quote is your audit trail, and it is also your cheapest hallucination filter: if the quoted text doesn't contain the value, the fact fails.
4. Resolve each fact to an existing record. "Acme Corp", "ACME Corporation" and "Acme" in a PDF header should land on one customer row, not three new entities. Match on stable identifiers first (domain, account ID, legal name), then on normalised names, and only then on fuzzy similarity. Create a new record only when nothing plausible matches.
5. Send conflicts to a person. If the contract says the term ends in March and the call notes say June, don't pick a winner. Keep both values with their quotes and put the disagreement in front of someone who can decide. Silent overwrites are how document extraction loses trust.
That is the method. Everything below is about doing steps 4 and 5 well, because that is where most DIY pipelines break.
Matching each fact to the right customer record, and what to do with conflicts
Matching is the hard step, because a wrong match is worse than no match. It attaches a contract to the wrong customer and nobody notices. Use a ladder, strongest signal first.
Exact identifiers. Account ID, tax number, email domain, contract reference. If the document carries one that appears in your database, match and stop.
Normalised names. Lowercase, strip suffixes like Inc, Ltd and Corporation, collapse whitespace. Match only when the result is unique.
Context. Same address, same signatory, same product line. Use these to break ties between two similar names, not as a match on their own.
Nothing plausible. Create a candidate record and flag it for review instead of guessing.
For a deeper treatment, see Entity Resolution for Knowledge Graphs Built by an LLM.
Conflicts need a different rule: never overwrite. When two sources give different values for the same field, store both, each with its quote or its table row, mark the field as disputed, and queue it for a person. A disputed value should never feed an answer until someone resolves it. The reviewer needs three things on screen: the two values, the evidence behind each, and which record they apply to. With anything less, review turns into guessing.
How Helix Foundry does it: documents plus Postgres, from the Acme Corp sample
Helix Foundry automates this loop. It connects your PostgreSQL database and your documents, has an ontology agent draft one ontology over both, and loads the result into HelixDB as one connected graph, with every value traced to the row or document quote it came from. Foundry is the app; HelixDB is the database it loads into. The code is Apache 2.0 at github.com/helixdb/helix-foundry.
The quickest way to see it is the built-in sample. Acme Corp is a made-up software company with contracts, call notes and an incident report, plus a Postgres source of customer records. To run Foundry on your own machine:
git clone https://github.com/helixdb/helix-foundry.git
cd helix-foundry
docker compose up -d --waitThen open http://localhost:3000. The local install is for one person on their own computer, so keep it on localhost. If you would rather not run Docker, Helix Cloud at foundry.helix-db.com offers a Set up with your agent route.
The flow on the sample maps onto the five steps above:
Sources. You add the Postgres source and upload documents as Markdown, text or PDF. The Postgres tables give the agent the customer records that documents must line up with.
Drafting. The ontology agent drafts types, links, rules and the documents each one comes from. That covers steps 2 to 4: it proposes the entity types, links them to your tables, and ties each element to its supporting documents.
Evidence. Every value is stored with where it came from, either a table row or a quote in a document. This is step 3's rule built into the structure.
Disagreements. Values the documents disagree on wait for review instead of being overwritten. That is step 5.
The Foundry docs describe the same sources, generation and review steps in more detail.
Reviewing the draft, loading it, and asking the Analyst with sources
The draft is a proposal, not a result. A person reviews it, checks the types and links against the goal question, resolves any waiting disagreements, and makes a version current. Only a current version loads into HelixDB. Review is where you catch an entity type that should be merged or a link pointing the wrong way.
Once a version is loaded, you explore it as a graph and ask questions through the Analyst, which answers in plain language and gives a source for every claim. On the Acme Corp sample you can ask something like which contracts reference the incident, then click through each claim to the table row or the document quote behind it. If a claim has no source, don't trust the answer.
This is also where changes get managed. Data and documents drift, and the ontology has to follow. How to Update an Ontology When Your Data Changes covers that, and Ontology Access Control covers who sees which facts. Every fact is grounded in a source, so a user who can't see a source can't see anything grounded by it.
Choosing a model, and where this approach falls short
Foundry can work with self-hosted models, your own inference, and bring-your-own-model. Pick by where your documents are allowed to go. If contracts can't leave your network, point Foundry at a local model; Build an Ontology With a Local LLM walks through that.
The approach has real limits, and they apply to the method as much as the tool:
Scanned PDFs. Extraction depends on readable text. A poor scan gives poor quotes, and a fact with a bad quote is a fact you can't verify.
Review is still human work. A draft ontology is only as good as the person approving it. Disagreements waiting for review don't resolve themselves.
Smaller models miss subtle clauses. Termination and renewal language is full of exceptions. Spot-check extractions against the quotes, whichever model you use.
One goal question at a time. An ontology built for renewals won't automatically serve a billing-dispute workflow. Add types deliberately.
Start with one goal question and the Acme Corp sample
Extracting an ontology from documents is a matching and review problem more than an extraction problem. The LLM is the easy part. The quote-backed facts, the record matching and the conflict queue are what make the result trustworthy. Run the Acme Corp sample first, ask the Analyst one question and click through to the quote behind each claim. Then clone helix-foundry, bring your own Postgres and a folder of contracts, and write your goal question before you press generate.