A semantic layer is context engineering for structured data. Benchmarks show governed definitions lift AI agent accuracy by 17 points. See why and how.

Ka Ling Wu
Co-Founder & CEO, Upsolve AI
10 min

When an AI agent reports the wrong revenue number, the instinct is to blame the model. A semantic layer for AI (governed definitions of your metrics, tables, and business rules) moves agent accuracy to production-grade, and no model upgrade closes that gap on its own. The semantic layer is context engineering applied to structured data, and it's the difference between an agent that answers questions and one that invents them.
Key Takeaways |
|---|
|
What Is a Semantic Layer for AI?
A semantic layer is a governed translation layer between raw data and the people, or agents, who query it. It defines what your business concepts mean ("active customer," "net revenue," "churn") and exactly how to compute them, once, in a form every consumer shares. For AI specifically, the semantic layer is the curated context an agent reads before writing a query, so it reasons over your definitions instead of guessing from column names.
A column called amt_ttl_pre_dsc means nothing to a language model. Neither does the fact that your company counts trials as customers in one dashboard and excludes them in another. Without a semantic layer, the agent fills those gaps with plausible assumptions and plausible is precisely what makes hallucinated numbers dangerous.
Why AI Agents Hallucinate Numbers
For two years the industry treated text-to-SQL as nearly solved, because models scored above 90% on academic benchmarks like Spider 1.0. Then Spider 2.0 rebuilt the test with real enterprise databases. An average of 800+ columns per database, multiple SQL dialects, project codebases and documentation to navigate, and the best result any model achieved was a 21.3% success rate. GPT-4o, from the same family that scored 91.2% on the academic version, managed roughly 13%. The models didn't get dumber; the context got real.
The pattern repeats everywhere researchers have run controlled comparisons:
dbt Labs' original experiment started from a data.world benchmark where GPT-4 answered enterprise questions correctly just 16.7% of the time against raw schemas; dbt's replication then hit 83% accuracy on the subset of questions the dbt Semantic Layer could address. Their 2026 rerun with current frontier models pushed semantic-layer accuracy to 98-100% for covered queries.
Cube's paired benchmark across Claude Opus, Claude Sonnet, and GPT-5-class models showed a consistent +17 to +23 point accuracy gain from adding a 4 KB semantic document and the gap did not close by swapping in a stronger model.
A pharmacovigilance study on Bayer's internal data (reported in the same benchmark literature) found GPT-4 jumped from 8.3% to 78.3% accuracy when given a business-context document. Narrowing the schema without that document still left the model failing about half the time. The definitions do most of the work, not schema reduction.
At Gartner's 2026 Data & Analytics Summit, one Gartner analyst predicted that 60% of agentic analytics projects relying on Model Context Protocol alone will fail for lack of a consistent semantic layer: MCP gives an agent access to your data, but access without meaning just lets it be wrong faster.
Grounded agents fail loudly (they refuse or ask for clarification). Ungrounded agents fail silently (they return a confident, specific, wrong number). Only one of those failure modes ends up in a customer-facing report.
The Semantic Layer Is Context Engineering for Structured Data
Context engineering says an LLM's output quality is determined less by the model and more by what you put in its window: the right information, in the right form, at the right time. The semantic layer is that discipline applied to your warehouse.
Prompt engineering was about phrasing a question cleverly; context engineering is about curating what the model knows before it answers. Ad-hoc schema dumps are the prompt-engineering era of data agents, paste the DDL and hope. A semantic layer is the context-engineering era: a deliberately curated, governed, versioned body of business meaning that every agent session inherits.
This framing also clarifies what the semantic layer is for in an AI stack. It's not a BI feature anymore. It's the structured-data half of your AI agent knowledge base, the counterpart to the documents and policies you feed agents for unstructured tasks. And like any context engineering artifact, it lives or dies on three properties:
Correctness: Definitions validated with business owners, not inferred from column names.
Currency: Context that updates when the warehouse changes, because stale semantics are worse than none, they're wrong.
Fit: Organized so an agent can load what it needs without drowning its context window in 27,000 column descriptions.
Get those three right and the model choice becomes almost boring.
What a Semantic Layer for AI Agents Actually Needs
Traditional semantic layers were built for BI tools that drag and drop. A semantic layer for AI agents has a different consumer, one that can read prose, ask clarifying questions, and make mistakes in creative new ways.
Governed Metric Definitions
The non-negotiable core: every ambiguous business term gets one canonical definition and one canonical way to compute it. "ARR excludes usage overages." "Active user means an event in the trailing 28 days." This is where hallucinated numbers actually come from. Not from bad SQL syntax, but from the agent picking a reasonable definition that isn't yours.
Ambiguity and Disambiguation Rules
Here's what agent-first semantic layers can do that YAML-first ones can't: encode when to ask. A definition file can say "'customer' has three meanings here. Always clarify which segment before answering." A traditional metric store can encode count(distinct customer_id); it cannot encode judgment. For agents, the disambiguation instructions are as valuable as the definitions themselves.
Table Selection and Join Gotchas
Every data team carries tribal knowledge about which of five similarly-named tables is the real source of truth, and which one silently undercounts. AngelList's data team documents these as explicit "gotcha" tables in their agent's context ("use this table for deal-level questions, never that one, and here's why") and describes each row as a bug that happened once and can never happen again. In most companies that knowledge lives in one analyst's head and leaves when they do. Written into the semantic layer, it becomes institutional memory converted into agent context.
Testing, Evals, and Observability
A semantic layer for humans is done when it's documented. A semantic layer for AI agents is done when it's tested. Golden questions with known answers, evals that run when definitions change, and observability into which context the agent actually used to produce each number. Without an eval loop, you can't tell whether your context is working or just present.
Code, YAML, or Markdown? The Form Is Changing
The traditional camp (the dbt Semantic Layer, Snowflake semantic views, Cube) treats the semantic layer as infrastructure: definitions in YAML or DDL, with a query-planning service that deterministically compiles metric requests into SQL. The guarantee is strong: a governed metric query cannot use the wrong definition, because the planner wrote the SQL.
The insurgent camp argues that if your primary consumer is an agent, you don't need a query planner at all. AngelList's engineering team made the sharpest version of this case. They replaced semantic-layer infrastructure with plain markdown (a business glossary, an auto-generated model catalog, and skill files) regenerated on every merge from the dbt manifest and even the upstream application code. Their observation cuts deep: an agent writes its own SQL, so what it needs isn't a planning service. It's legible, current, well-organized text. And documentation that regenerates itself is the only documentation that stays correct.
Both camps are right about different things, and the honest synthesis looks like this:
Approach | Guarantee | Strength | Weakness |
Compiled semantic layer (YAML + planner) | Deterministic - canonical definition, every time | Correctness on covered metrics approaches 100% | New DSL to maintain; covers only what you've modeled |
Context corpus (governed prose) | Probabilistic - very likely correct | Encodes ambiguity, judgment, and gotchas; agent-agnostic | Correctness rests on doc quality and model capability |
Nothing (raw schema) | None | Zero setup | ~21% task success at best on real enterprise workloads (Spider 2.0) |
Whether your definitions compile into SQL or into an agent's context window, what makes them a semantic layer is that they're canonical, validated, versioned, and current. What both camps agree on completely: an agent improvising against a raw schema is how you get hallucinated numbers.
How Upsolve Approaches the Semantic Layer for AI
This problem is the reason Upsolve AI exists. Most AI analytics failures we see follow the same script: warehouse centralized, LLM bolted on top, magical demo; then the agent confuses ARR with run rate in front of a customer, and the project gets shelved. It was never a model problem. It was a context problem.
Upsolve's answer is to treat the semantic layer as one piece of a broader context infrastructure for data agents, built in Agent Context Studio across three layers:
Structure: schemas, lineage, and table relationships; the map of what exists.
Meaning: your metric definitions, business rules, and disambiguation logic; the governed semantic layer itself.
Trust: verified answers, evals against golden questions, and full observability into how each answer was produced.
Deliberately, this takes no side in the YAML-versus-markdown debate. If you already have a dbt project, Upsolve consumes it; if you don't, you can start without a pre-built semantic layer and encode context as you go. The platform builds and maintains the semantic layer with you rather than demanding one. Either way, the Upsolve Data Agent behaves like a strong analyst: it uses the governed definitions when they exist, and asks clarifying questions when they don't.
Frequently Asked Questions
What is a semantic layer in AI?
A semantic layer in AI is the governed business context (metric definitions, table relationships, and business rules) that grounds an AI agent's queries against structured data. It ensures the agent computes "revenue" or "active customer" using your organization's canonical definitions instead of inferring meaning from raw column names.
Why do AI agents hallucinate numbers without a semantic layer?
Because raw schemas are ambiguous and models fill ambiguity with plausible assumptions. On the Spider 2.0 enterprise benchmark, the best agentic setup solved only 21.3% of tasks, and pure text-to-SQL from schema context alone solved under 6% and the failures return specific, confident, wrong numbers rather than errors.
Is a semantic layer the same as a knowledge base for AI agents?
It's the structured-data half of one. An AI agent knowledge base spans documents, policies, and procedures; the semantic layer is the portion that governs how the agent interprets and queries your warehouse. In practice they converge, modern semantic layers increasingly include prose context, gotchas, and disambiguation rules, not just metric formulas.
Do I need dbt to build a semantic layer for AI?
No. The dbt Semantic Layer is one strong implementation, but the essential ingredient is governed, current definitions; which can also live in database-native semantic views, a dedicated platform, or version-controlled context files. Tools like Upsolve work with an existing dbt project or generate the semantic layer for you.
How much does a semantic layer improve AI accuracy?
Substantially, across every controlled comparison. Cube's paired benchmark measured a +17 to +23 percentage-point gain across three frontier models, a pharmacovigilance study on Bayer's data measured +70 points, and dbt Labs measured 98-100% accuracy for queries covered by its Semantic Layer. Notably, upgrading the model without adding context recovered almost none of that gap.
How long does it take to build a semantic layer for AI agents?
Days to start, ongoing to mature. You can begin with your 10-20 most ambiguous metrics and highest-traffic tables, then grow one definition and one gotcha at a time; every gap an agent surfaces becomes the next addition. Auto-generation from existing assets (dbt manifests, warehouse metadata) compresses the timeline dramatically compared to hand-authoring everything upfront.
Sources
ICLR / Lei et al.: Spider 2.0: Evaluating Language Models on Real-World Enterprise Text-to-SQL Workflows. https://proceedings.iclr.cc/paper_files/paper/2025/file/46c10f6c8ea5aa6f267bcdabcb123f97-Paper-Conference.pdf
Cube: Why Semantic Layers Make LLM Analytics Reliable: A Paired Benchmark Across Three Frontier Models. https://cube.dev/blog/why-semantic-layers-make-llm-analytics-reliable-a-paired-benchmark-across-three-frontier-models
arXiv: Semantic Layers for Reliable LLM-Powered Data Analytics (includes the Bayer/JAMIA Open paired comparison). https://arxiv.org/abs/2604.25149
dbt Labs: Semantic Layer as the Data Interface for LLMs. https://www.getdbt.com/blog/semantic-layer-as-the-data-interface-for-llms
dbt Developer Blog: Semantic Layer vs. Text-to-SQL: 2026 Benchmark Update. https://docs.getdbt.com/blog/semantic-layer-vs-text-to-sql-2026
Gartner: Top Predictions for Data and Analytics in 2026. https://www.gartner.com/en/newsroom/press-releases/2026-03-11-gartner-announces-top-predictions-for-data-and-analytics-in-2026
Atlan: What Is a Semantic Layer for AI Agents? (reporting Gartner's MCP failure prediction). https://atlan.com/know/ai-agent/semantic-layer-for-ai-agents/
AngelList Engineering: The Semantic Layer Nobody Maintains. https://www.angellist.com/blog/the-semantic-layer-nobody-maintains
MIT Sloan: Why a Semantic Layer Is Pivotal to Your AI Strategy. https://mitsloan.mit.edu/ideas-made-to-matter/why-a-semantic-layer-pivotal-to-your-ai-strategy
Upsolve AI: Deploy Accurate and Trusted Data Agents. https://upsolve.ai/

Try Upsolve for Embedded Dashboards & AI Insights
Embed dashboards and AI insights directly into your product, with no heavy engineering required.
Fast setup
Built for SaaS products
30‑day free trial






