Data Governance

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.

Where text-to-SQL accuracy actually lands
SetupReported accuracySource
Code agent (o1-preview) on Spider 2.0 enterprise tasks, at launch21.3% solvedSpider 2.0 paper, arXiv
Same framework on academic Spider 1.091.2% solvedSpider 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 queriesNear-100%dbt Labs, 2026
Sources: arXiv (Spider 2.0, Lei et al.), dbt Labs Semantic Layer vs. Text-to-SQL 2026 benchmark update.

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.

  1. 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.
  2. A contract schema. A JSON Schema that validates every registry file: owner, definition, grain, freshness SLA, change policy. CI rejects anything malformed or ownerless.
  3. A review gate. Pull requests touching a definition block require approval from the metric's owner. GitHub CODEOWNERS handles this with zero custom code.
  4. 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.
  5. 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.

Sources

Frequently asked questions

Do we need dbt to build a semantic layer?
No. dbt MetricFlow is one implementation; Cube, AtScale, LookML, and Snowflake's semantic views all encode the same pattern: business terms mapped declaratively to physical SQL and compiled by one engine. Pick whatever sits closest to your existing stack. The non-negotiable properties are version-controlled definitions, deterministic query resolution, and an API the agent can be restricted to. The vendor logo matters far less than whether your definitions live in git with an owner attached.
What is the difference between a data contract and a metric contract?
A data contract governs the shape of data moving between systems: schemas, types, delivery SLAs between a producer service and the warehouse. A metric contract sits one layer up and governs meaning: the exact measure, filters, and grain behind a business number, plus who owns it and how changes get approved. You can run metric contracts without formal data contracts underneath, though pipeline schema drift will eventually make you want both.
Can't we just put the metric definitions in the agent's system prompt?
You can, and it works until the prompt and the warehouse disagree. Prompts are unversioned prose with no CI, no owner approval flow, and no guarantee the agent applies them consistently across phrasings. A semantic layer makes the definition executable rather than advisory: the agent selects a metric and the engine compiles the SQL, so there is no step where the model interprets prose. Prompts are fine as documentation. They are weak as enforcement.
What should the agent do with questions the semantic layer doesn't cover?
Refuse, visibly, with a pointer to the registry. The tempting fallback is letting the agent write raw SQL for uncovered questions, which quietly reintroduces the original failure mode through a side door. A better pattern: log every refused question, review the log weekly, and promote the most-requested metrics into the registry with a proper contract. Refusals become your prioritized backlog, and coverage grows in proportion to real demand.

Free tools for this topic

FREE TOOLAttribution DoctorA media-mix model that runs in your browser.FREE TOOLUTM Campaign BuilderClean tracking links your analytics will thank you for.PLAYBOOKThe First-Party Data PlaybookMeasurement that survives privacy — and gets sharper.

Keep reading

AI & MLAI Audience Segmentation in SaaS: The Data Enrichment PlaybookRead →EcommerceAI Customer Insights for Ecommerce: Data Enrichment PlaybookRead →EcommerceAI Audience Segmentation in Ecommerce: Predict Churn and Grow CLVRead →
CATALIST NEWSLETTER

Monthly dose of growth marketing.

Get marketing tips, narratives, guides, and playbooks delivered to your inbox.