What it does

A metadata-aware SQL agent that answers business questions three ways at once: (1) the generated SQL itself, (2) a plain-English explanation of exactly which tables the query touched and how they relate — upstream lineage, glossary terms, PII flags — pulled from a DataHub-shaped metadata catalog, and (3) a statistical sanity check that compares the result against that metric's historical distribution and flags it when it looks like an outlier, before anyone reports the number.

Inspiration

Analysts get asked the same three questions over and over: "what's the number," "where did it come from," and "can I trust it." Most NL-to-SQL tools answer the first and ignore the other two, so a business user gets a confident-looking number with no way to tell if it's grounded in the right tables or a fluke.

How we built it

The whole pipeline runs with zero paid API keys. The natural-language-to-SQL layer is a fast, fully local template-matching engine, with a documented drop-in point for a free local LLM via Ollama for more open-ended phrasing. The sample dataset is a small SQLite e-commerce schema with over a year of order history and a deliberately planted demand-spike anomaly to demonstrate the flagging logic. The metadata catalog is authored in DataHub's real entity shape — dataset urns, schema fields, upstream lineage edges, glossary terms — so it can be pushed into a real, self-hosted, open-source DataHub instance (datahub docker quickstart) with the included ingestion script, with no changes to the agent itself.

Challenges we ran into

Getting the anomaly detector to distinguish a genuine outlier from normal month-to-month variance required tuning the z-score baseline against a full 19 months of seeded history rather than a shorter window. Keeping the NL-to-SQL layer free of paid API keys while still handling a reasonable range of phrasing also took several iterations of the template matcher.

Accomplishments that we're proud of

A fully working, locally testable pipeline (10/10 tests passing) that catches a planted demand spike (z ≈ +75.7) and correctly explains data lineage including PII flags, without requiring a single paid API key.

What's next

Swap in a real self-hosted DataHub GMS instance by default, expand the NL2SQL template coverage, and add the optional local Ollama reasoning layer for fully open-ended questions.

Built With

Share this project:

Updates