Problem
Large healthcare companies keep patient data in claims, labs, pharmacy and provider systems, and every acquisition adds another database and stack. A risk signal usually lies in a combination of rows from several tables, so finding high-risk patients takes SQL of 50 to 100 lines that nobody understands after the author leaves. LLM agents that write SQL over raw tables need every column explained in context. A query that joins the wrong tables still returns a number with no error.
Example from the article: with 50 tables the agent may face 1,500 columns, each needing an explanation and its join rules. Joining the patient table with doctor salary would run and return a result.
Solution in brief
Put an ontology graph over the existing tables. Tables map to node types (patient, visit, condition) and edge types ("has condition"), and the LLM writes a graph pattern instead of joins. The engine checks each query against the ontology, rejects impossible patterns with an error message, and the LLM retries until the query is valid.
Questions this case answers
- How to make an LLM agent answer analytical questions over a complex multi-table schema without returning plausible but wrong numbers
- How to validate a generated query against a declared model of entities and relations before it runs
- How to make an LLM agent answer analytical questions over a complex multi-table schema accurately
- How to stop a text-to-SQL agent from returning plausible but wrong numbers
Tools and methods
- PuppyGraph — zero-ETL graph layer over tables; the speaker's product
- Delta Lake and Unity Catalog — storage and governance read in place
- Ontology graph — self-explanatory nodes and edges mapped to tables
- LLM graph-query generation with validation and retry — replaces text-to-SQL
- OMOP common data model — healthcare standard used in the demo
Google or a one-time email code. No password.