The problem
As more teams built AI agents, each one wrote its own SQL against the warehouse with its own idea of what a metric meant. Answers disagreed, and nobody could easily audit what an agent was allowed to see.
The goal was one governed path: any agent asks a question, gets the right data model, uses the shared definition, and can only read what it should.
From business problem to technical problem
The first job is translation. Here is how the ask changed shape before any code was written.
- Business askCan anyone ask a data question in plain language and trust the answer?
- Technical questionRoute each question to the right governed data model, query it through shared definitions, and enforce what each agent may read.
- What success looks likeRetrieval and answer quality measured on an evaluation set before every release, and access that can be audited.
Paths I weighed
There was more than one reasonable way to do this. These are the options I compared and why I picked one.
Let each agent write raw SQL
Upside. Fastest start.
Cost. Inconsistent metrics, broad access, and nothing to audit.
Train a text-to-SQL model on our schema
Upside. Fluent queries.
Cost. Still no shared definitions, brittle as the schema changes, and costly to keep current.
Semantic layer, catalog, and an MCP server
Upside. One set of definitions, least-privilege access, and it works with any model or agent.
Cost. Slower to build and needs modeling discipline.
What I built
- Semantic layerBusiness definitions as code, on dbt models
- Data catalogVersioned descriptions of every model
- RetrievalFinds the right models for a question
- MCP serverLeast-privilege, read-only query tools
- Release gatesEvaluation runs before agents see a change
The path started with a hackathon text-to-SQL prototype, which I evolved into a deployed RAG analytics agent. From there I introduced the Model Context Protocol (MCP) to the data team and led the design of a server that exposes the warehouse to any agent through the same semantic layer and catalog.
How it got built, scaled, and fixed
- Build
A hackathon text-to-SQL prototype proved the demand.
- Scale
It became a deployed RAG analytics agent. Introducing MCP then turned one app into a governed path any agent can use.
- Fix
Evaluation showed retrieval, not query writing, was the bottleneck, so that is where the effort went. Release gates now stop catalog changes that would regress answers.
Decisions that mattered
Definitions live in one place
Agents query the semantic layer instead of reinventing metric logic, so two agents asked the same question give the same answer.
Retrieval is the bottleneck
A fluent query on the wrong table is still wrong, so improving how agents find the right data model paid off more than any prompt change.
Least privilege by default
Agents get scoped, read-only access. What each one can see is explicit and auditable.
Gate releases on evaluation
Catalog and server changes pass an evaluation suite before they ship, so improvements for one question do not quietly break another.
A version you can run
The production system stays private, so I rebuilt the approach from scratch as an open-source project, governed-warehouse-mcp. It runs on a synthetic cross-border freight warehouse, and no code, schema, or data from the production system is used.
It makes the same bets as this page: agents ask for governed metrics by name, and agent-written SQL goes through the same access policy and is regenerated from a checked syntax tree before it runs. It also makes some of the tradeoffs concrete. Search is lexical and deterministic, with two rankers fused: on a dev set and a separately written held-out set, each ranker alone wins one and falls behind on the other, and fusion holds up on both. An evaluation harness grades tool-calling agents on answers, governance, and prompt injection planted in the data, and its graders are tested against planted failures before they are trusted.
What transfers
Agent quality is mostly a data problem. In my experience, shared definitions, good retrieval, and explicit permissions matter more for answer quality than which model you pick. For agents, the semantic layer is the interface that matters.
Methods
Collaborative work with product and engineering partners; this page describes my contribution. Diagrams are simplified.