guide
guide8 min read

Semantic Layer vs Text-to-SQL: How Much Accuracy Does a Semantic Layer Add for AI Agents?

What a small public benchmark shows, where it stops, and how to decide which path each question should take

In dbt Labs' April 2026 benchmark, grounding Claude Sonnet 4.6 in a semantic layer raised accuracy from 90.0% to 98.2% on a modeled project, and GPT-5.3 Codex went from 84.1% to 100.0%. The dataset is small, only 11 questions, so we treat the result as strong directional evidence rather than a universal number. The practical lesson is that a semantic layer trades coverage for correctness.

Key Takeaways

  • •On dbt Labs' modeled project, a semantic layer lifted Claude Sonnet 4.6 from 90.0% to 98.2% and GPT-5.3 Codex from 84.1% to 100.0%.
  • •On the original, unmodeled schema, the gap was smaller: 64.5% for text-to-SQL versus 72.7% for the semantic layer in 2026.
  • •Questions the semantic layer cannot express scored 0% and returned an error, while text-to-SQL attempted them and could return plausible wrong answers.
  • •The benchmark is vendor-authored and uses 11 questions on one roughly 15-table dataset, so treat the percentages as sensitive to individual questions.
  • •The workable pattern is routing: use the semantic layer for governed metrics and text-to-SQL for exploration, with the agent saying which path it took.

What the benchmark actually measured

The dbt Labs write-up uses an insurance dataset with about 15 normalized tables and 11 questions, each run 20 times per configuration. It compares text-to-SQL on the original schema, a minimal semantic layer, a modeled semantic layer, and text-to-SQL on the modeled data. Claude Sonnet 4.6 and GPT-5.3 Codex carry the main results, with a reasoning-effort sweep on other models.

Two details matter for anyone reading the headline. First, the modeled numbers came after adding three dbt models, and that modeling helped both approaches, so part of the lift is better data shape rather than the semantic layer alone. Second, the full data and costs are published in the open-source dbt-llm-sl-bench repository, which means you can rerun it against your own schema instead of trusting our summary.

The authors also note that the text-to-SQL arm received the full schema as context. That is not practical for large warehouses, so real-world text-to-SQL on a few thousand tables would likely score lower than the benchmark suggests.

Why grounding helps: the model stops inventing joins

Free-form text-to-SQL asks the model to pick tables, choose join keys, apply filters, and define the metric all at once. Each choice is a chance to be plausibly wrong. A semantic layer removes most of those choices. The metric is defined once in YAML, and the model only selects a metric and dimensions to slice by.

MetricFlow, the engine behind the dbt Semantic Layer, builds joins from entity key types rather than arbitrary join logic, which the MetricFlow docs say avoids fan-out and chasm joins. It supports 5 metric types: simple, ratio, derived, cumulative, and conversion. Those are exactly the places where hand-written SQL most often double counts or applies the wrong denominator.

That is why a question like "What was net revenue last quarter by region?" is a good fit. The definition of net revenue is not the model's guess. It is a governed object the agent calls.

The cost: coverage and the 0% rows

The benchmark is candid about the downside. On the original schema, accuracy across all 11 questions was 72.7% for the semantic layer in 2026, up from 60.5% in the 2023 GPT-4 baseline, while text-to-SQL went from 32.7% to 64.5%. Within the semantic layer's scope, both 2026 models scored 100%. Questions needing too many entity hops for MetricFlow scored 0% in every run.

That 0% is not the same kind of failure as a wrong text-to-SQL answer. The semantic layer returns an error, which a person or agent can see and route around. Text-to-SQL returns a number that looks fine. For an agent that reports to executives, a loud refusal is usually the better failure mode.

The cost is modeling work. Someone has to define the semantic models and metrics, and every question outside that surface needs either new modeling or a fallback path.

How to read an 8-point lift honestly

Going from 90.0% to 98.2% sounds small, but in error terms it is a drop from 1 wrong answer in 10 to roughly 1 in 55. For KPI reporting that is the difference between occasional corrections and rare ones. We would not generalize beyond that, though. Eleven questions means a single question flips the aggregate several points.

The benchmark also found that higher reasoning effort made little difference to semantic-layer accuracy and mostly added latency, with over 20 seconds on the highest setting versus about 8 seconds on high for the GPT models. In other words, once the question is constrained, extra thinking time buys little.

Our advice: rerun the open benchmark shape on your own ten to twenty real questions before you commit modeling budget. Your join depth and metric ambiguity will decide the result, not ours.

A routing pattern that uses both

The authors recommend the semantic layer where accuracy matters, such as KPIs, board reporting and audits, and text-to-SQL for ad hoc exploration. We agree, and we would add that the agent must tell the reader which path produced the number. An answer from a governed metric and an answer from exploratory SQL deserve different levels of trust.

  • •Governed metric exists: call the semantic layer, return the metric name and definition with the answer.
  • •Metric missing but tables are documented: fall back to text-to-SQL, label the result as exploratory, and list the assumptions.
  • •Question spans too many entity hops: say so, and propose the modeling change instead of guessing.
  • •Result will feed a dashboard or a report: require the governed path or a human review.

The Insights Agent works this way: it grounds text-to-SQL in the semantic layer, returns the analysis with citations and assumptions, and chains with the catalog and quality agents so a question about a stale table is flagged before the answer goes out.

Where context beyond the semantic layer matters

A semantic layer defines metrics. It does not tell the agent that a table was deprecated last week, that a column is PII, or that yesterday's load failed. Those facts live in the catalog, the quality checks and the lineage graph. An agent that answers from metrics alone can still be right about the definition and wrong about the data.

This is why we expose each capability as an MCP server. The Model Context Protocol specification defines resources, prompts and tools as the three server features, so an agent in Claude Code or Cursor can read a metric definition, a freshness score and an access policy through the same interface. The Catalog Agent supplies the discovery side, federating across the catalogs you already run.

Questions like "Show freshness scores for all gold tables" or "Is the customer_id join safe after the migration?" need that wider context. The semantic layer alone cannot answer them.

A short plan for your own team

Start by collecting 15 to 20 questions your analysts actually get, and tag each as metric-shaped or exploratory. Run both paths against them and record the answers beside a known-correct result. This is the same evaluation-gate habit we recommend before any agent acts on your data, and it takes an afternoon.

Then model only the metrics that appear repeatedly in the metric-shaped group. Resist modeling the whole warehouse. The benchmark shows that three added models improved results for both approaches, so small, targeted modeling goes a long way.

Finally, make the routing visible. Whatever agent you use should state the path, the metric or tables used, and the assumptions. A reader who can see the path can decide how much to trust the number.

Frequently Asked Questions

Does a semantic layer always beat text-to-SQL?

No. In the dbt Labs benchmark it won where questions fit the modeled metrics, but it scored 0% on questions that exceeded its entity-hop reach, while text-to-SQL at least attempted them. It wins on correctness within scope and loses on coverage. The right choice depends on the question.

Is the 98.2% figure reliable enough to plan around?

Treat it as a directional signal. The benchmark has 11 questions on one dataset and was authored by a vendor that sells a semantic layer. The data and code are open in the repository, so you can reproduce it, and you should test on your own questions before you rely on the number.

Can I use text-to-SQL safely without a semantic layer?

Yes, for exploration, if the agent labels results as exploratory, lists its assumptions and cites the tables used. Avoid sending unlabeled text-to-SQL output into board reporting or audit work, since a plausible wrong answer is harder to catch than an error.

Do I need to rebuild my stack to try this?

No. Data Workers is MCP-native, so the Insights Agent works inside the clients your engineers already use, such as Claude Code and Cursor, and the open-source edition runs locally and is read-only by default. You can test the routing pattern on a handful of questions before changing any models.