Skip to content

From Documents to Graph

Building KGs from Documents with LLMs

11 min+105 XPStep 1/11

Extraction is constrained generation, not a prompt

The naive prompt — 'extract all entities and relations' — returns free-form mush: invented predicates, inconsistent names, every document in a different dialect. Production extraction is schema-guided: hand the model your ontology (allowed entity types, allowed predicates, domain/range rules) and require structured output that conforms to it. JSON-schema-constrained decoding or function calling turns 'returned an invalid predicate' into a parse error, not a silent write.

The ontology does double duty: it constrains output and teaches the model what matters — listing ADVERSE_EVENT_OF in the schema is how the model learns to look for it.