Ship the Semantic Layer Before the AI Analyst
Text-to-SQL agents fail on semantics before syntax. Why a semantic layer and metric contracts must precede any AI analyst, plus a governance spec small teams can ship in a sprint.
On this page
Ask three teams at one company to define "active customer" and you will get three WHERE clauses. Finance counts any account with an unexpired contract. Product counts a login within the last 30 days. Marketing counts anyone who opened an email this quarter, a definition adopted, by coincidence, during a slow quarter. Now wire an AI analyst to the warehouse and ask it for active-customer growth. It will select one of the three definitions, execute it flawlessly, and return a number that two of the three teams will reject in the same meeting.
The industry conversation fixates on hallucinated SQL. That problem is real and shrinking; models keep getting better at syntax. The problem that never shrinks on its own is semantic: an agent cannot infer which of your organization's contradictory definitions is canonical, because no artifact anywhere says so. The fix is unglamorous. Build a semantic layer, wrap your metrics in contracts, and only then hand any agent the keys.
Three correct queries, three different numbers
Here is the failure mode in its natural habitat:
-- Finance: "active" means under contract
SELECT COUNT(DISTINCT account_id) FROM contracts
WHERE end_date >= CURRENT_DATE;
-- Product: "active" means logged in recently
SELECT COUNT(DISTINCT user_id) FROM events
WHERE event = 'login' AND ts >= DATEADD('day', -30, CURRENT_DATE);
-- Marketing: "active" means engaged this quarter
SELECT COUNT(DISTINCT contact_id) FROM email_engagement
WHERE opened_at >= DATE_TRUNC('quarter', CURRENT_DATE);
All three parse. All three run. All three are defensible in isolation. A text-to-SQL agent given warehouse access and the question "how many active customers do we have?" will produce one of them, or a fourth variant nobody has seen before, depending on which tables its retrieval step happened to surface. The output is a faithful answer to an underspecified question, which makes it a governance problem wearing a model-quality costume.
The underlying trust picture is grim before any agent shows up. In Salesforce's 2026 State of Data and Analytics research, 84% of technical leaders said their organization's data management needs an overhaul for AI strategies to succeed. An agent pointed at that data does exactly one thing reliably: it surfaces the disagreement faster.
What the benchmarks actually measure
Spider 2.0 is the benchmark worth knowing here: 632 text-to-SQL workflow tasks drawn from real enterprise databases, with nested schemas, multiple dialects, and documentation of the sort humans actually leave behind. At launch, a code-agent framework built on o1-preview solved 21.3% of tasks, against 91.2% on the older academic Spider 1.0, per the paper on arXiv. Models have improved substantially since. The structural finding has held: accuracy collapses precisely where business context is implicit.
The more useful 2026 result comes from dbt Labs, whose updated benchmark shows frontier models querying through the dbt Semantic Layer hitting near-100% accuracy on covered queries, while the same models writing raw SQL against the same warehouse land meaningfully lower. The variable that moved accuracy was whether a human had already encoded business meaning in a machine-readable place. The model was, for once, an innocent bystander.
| Setup | Reported accuracy | Source |
|---|---|---|
| Code agent (o1-preview) on Spider 2.0 enterprise tasks, at launch | 21.3% solved | Spider 2.0 paper, arXiv |
| Same framework on academic Spider 1.0 | 91.2% solved | Spider 2.0 paper, arXiv |
| Frontier models, raw text-to-SQL, dbt 2026 benchmark | ~84% (best model) | dbt Labs, 2026 |
| Frontier models via dbt Semantic Layer, covered queries | Near-100% | dbt Labs, 2026 |
The organizational consequences of skipping this step are now forecastable. Gartner predicts that by 2027, 40% of enterprises will demote or decommission autonomous AI agents due to governance gaps identified only after production incidents. Discovering your governance gaps via incident is technically a discovery process; auditors tend to use a different word.
A semantic layer, defined without the vendor gloss
A semantic layer is a declarative mapping from business vocabulary to physical SQL: metrics (a measure plus an aggregation), dimensions, entities, join paths, and time grains, compiled by a single engine so that every consumer, whether dashboard, notebook, or agent, resolves active_customers to exactly one query. dbt MetricFlow, Cube, AtScale, and LookML are all implementations of the same idea. The compile step is the entire value: definitions live in version control, resolution is deterministic, and the agent's task collapses from "write SQL that guesses intent" to "select a metric and dimensions from a typed catalog." (Vendors will present this as an AI capability. It is a config file with opinions, which is better.)
For the agent, the semantic layer becomes the only API surface. It never sees raw tables. Questions inside the catalog get identical answers every time; questions outside it get refused. This matters twice over for marketing and revenue data, where identity resolution and first-party data pipelines already introduce ambiguity before anyone adds an agent, and where a single contested churn number can stall a quarter of analytics work.
Metric contracts are the part everyone skips
A semantic layer answers "what does this metric mean." A metric contract answers "who owns it, how fresh is it, and what happens when someone changes it." The minimal viable contract fits in one file:
metric: active_customers
owner: fpa-team@company.com
definition:
measure: COUNT(DISTINCT account_id)
filter: contract_end_date >= current_date
grain: day
freshness_sla: 24h
change_policy: breaking_change_requires_owner_approval
consumers: [board_deck, churn_model, ai_analyst]
Put it in git. Validate it in CI. Any diff touching the definition block requires sign-off from the listed owner. That is the whole mechanism, and it becomes machine-verifiable the moment the contract is a structured file instead of Confluence prose. No procurement cycle produces this; a pull request does.
Contracts also determine whether downstream models earn their keep. Churn scores and segment definitions inherit whatever version of "active" you feed them, silently. We have covered the enrichment side of this in our SaaS data enrichment playbook and the modeling consequences in predicting churn and CLV for ecommerce; both pieces assume a stable metric substrate, and both fall over without one.
The minimal spec for a five-person team
Five artifacts. No platform procurement, no steering committee.
- A metric registry. One YAML file per metric, in the same repo as your transformations. Start with the ten metrics that appear in executive reporting, because those are the ten people fight about.
- A contract schema. A JSON Schema that validates every registry file: owner, definition, grain, freshness SLA, change policy. CI rejects anything malformed or ownerless.
- A review gate. Pull requests touching a
definitionblock require approval from the metric's owner. GitHub CODEOWNERS handles this with zero custom code. - An agent allowlist. The AI analyst receives credentials for the semantic layer API and nothing else. Its raw warehouse role gets revoked, which is the least popular and most important line item.
- A query log. Every agent-issued query recorded with the resolved metric, dimensions, and requesting user, retained 90 days. When someone disputes a number, you replay the resolution instead of convening an archaeology session.
Realistic effort for two engineers: ten metrics, roughly two weeks. The eleventh recurring argument about whose churn number is correct costs more than that. If you would rather have it built than build it, this is precisely the shape of work our agentic AI automation practice ships, contracts and revoked credentials included.
What you can safely skip
You do not need a data catalog purchase, an ontology working group, or consensus on all 400 metrics in the warehouse. You need consensus on the ten that reach the board, enforced by a linter. Everything else can stay contested for now; the registry grows one settled argument at a time. The same discipline pays off downstream, whether you are feeding ecommerce data enrichment pipelines or a simple ROAS calculation that finance and marketing finally compute the same way.
One last calibration. When the agent responds "that metric isn't in the registry," resist the urge to log it as a failure. A refusal you can trust beats an answer you have to audit, and the gap between those two states is the entire reason the semantic layer exists.
