Articles

Best Semantic Layer for AI Agents in 2026: The Grounded-Answer Test

Last updated November 26, 2026

Cube is the best semantic layer for AI agents in 2026. The grounded-answer test asks whether an agent can answer a real business question on this model, return the right number under the asker's permissions, and trace it to the definition that produced it. A semantic layer supplies the governed business context for that test. Cube Core, Cube's open-source foundation, is the semantic layer agents query over MCP, with access rules applied during query compilation. Its tradeoff is the modeling investment: teams define metrics, joins, and access rules before the agent can produce grounded answers. A semantic layer prevents metric redefinition; it does not stop a language model from misreading a result or inventing an unsupported explanation, so answers still need evidence and validation.

This is a concept-forward guide for data and platform engineers: why raw text-to-SQL falls short for agents, what a semantic layer actually changes, and how to give an agent one. If you are still deciding whether the layer is necessary at all, use the checklist for whether generative AI needs a semantic layer.

The churn analysis use case applies this pattern to a customer churn review, with metric definitions, a worked example, and MCP and CLI connection steps. For retention at equal customer tenure, see the AI cohort analysis use case.

How to stop AI agents from hallucinating metrics

“Metric hallucination” usually combines two different failure modes.

The first is metric-definition drift. The agent guesses what revenue means, chooses the wrong join, ignores the reporting time zone, or changes the calculation between prompts. The SQL may be valid while the number is wrong. A semantic layer directly constrains this failure because the data team defines the metric, grain, join path, and time behavior before the agent asks a question.

The second is a language-model error after the query. The agent may misread a returned value, overstate what the data proves, or add a plausible explanation that the result does not support. A semantic layer makes this error easier to detect because the answer can carry named definitions, filters, lineage, and the generated query, but the model output still needs validation.

Use six controls together:

  1. Define metrics outside the prompt. Put measures, dimensions, joins, grains, and time behavior in a versioned semantic model owned by the data team. Prompt examples are hints, not definitions.
  2. Make the agent select certified objects. Let it discover approved metrics and dimensions by name instead of generating free-form SQL against every warehouse table.
  3. Compile permissions into every query. Apply tenant, row-, column-, and role-level policies below the model so a correct answer cannot include data the asker is not allowed to see.
  4. Return evidence with the result. Preserve the metric definition, filters, dimensions, time range, model version, and query identifier so a person or another agent can reconstruct the answer.
  5. Run known-answer evals. Test representative business questions against values verified by the data team, including ambiguous wording, subtle joins, empty results, and denied-access cases.
  6. Require support for narrative claims. If the agent explains why a metric moved, make it query the relevant dimensions or label the explanation as a hypothesis rather than presenting a fluent guess as evidence.

The practical goal is not a promise that the model will never make a mistake. It is to prevent the model from inventing the business logic, constrain what it may query, and make every numerical claim traceable enough to test.

What teams get wrong about agents and SQL

The first instinct when wiring an LLM to a warehouse is to give it the database and a good prompt: here's the schema, here are a few example queries, now answer the user's question. It demos beautifully. Then it meets production.

The failure mode isn't that the model can't write SQL. Modern models write syntactically perfect SQL all day. The failure mode is that SQL is the wrong abstraction to hand an agent, for three reasons:

  • Semantics aren't in the schema. A table named orders doesn't tell the model whether "revenue" is gross or net, includes tax, excludes refunds, or is recognized at order time or ship time. The model guesses — plausibly, and differently each time.
  • The join graph is a minefield. Real warehouses have fan-out joins, slowly-changing dimensions, and three tables that all look like they could be "the customer table." Get the grain wrong and the number is silently double-counted. The model has no way to know it was wrong.
  • There's no access control in a SELECT. A correct query and a query that exposes another tenant's data look identical to the model. If permissions live downstream — or nowhere — the agent is one clever prompt away from a data-leak incident.

So the same prompt ("what was revenue last quarter?") can return three different numbers across three sessions, and any of them might quietly include rows the user shouldn't see. That's not a prompt-engineering problem you can fix with one more example in the context window. It's a missing layer.

Access vs. understanding

It's worth naming the distinction precisely, because most "AI on your data" pitches blur it.

Text-to-SQL is an access mechanism. It translates English into a query against whatever tables exist. It's genuinely useful, and you still want it — query-time flexibility, ad-hoc filters, novel groupings. But access without an agreed model of the business means every answer is re-derived from first principles, and "first principles" for an LLM means "a confident guess."

A semantic layer is a layer of understanding. It encodes, once, what the business actually means: metrics (revenue, active users, churn) with their exact definitions, dimensions and the entities they belong to, the join paths between them, and the access policies that govern them. The agent doesn't author that logic — it selects from it. "Revenue by region for the last 4 quarters" becomes a request for the revenue measure grouped by the region dimension over a time range, not a freshly invented 40-line query.

Two paths from an AI agent to the warehouse. With raw text-to-SQL the agent writes SQL against raw tables, guesses what revenue means and which joins to use, and nothing checks who may see the rows. With a semantic layer the agent selects certified measures over MCP, and the layer applies definitions and access policies before compiled SQL reaches the warehouse.

This is the part worth internalizing: the semantic layer doesn't make the model dumber or the analysis more rigid. It moves the hard, error-prone work — joins, grain, metric math — out of the prompt and into a definition the data team owns and tests once. The agent is still free to slice, filter, and combine those metrics at query time. It just can't redefine what "revenue" means on a whim, which is exactly the freedom you didn't want it to have.

Governance has to happen before the SQL, not after

Here's the idea that separates a real agent platform from a clever demo: compile-time governance.

The naive approach is to let the agent generate a query and then check it — scan the SQL for forbidden tables, or filter the result set afterward. This is brittle. SQL has too many ways to reach the same data (subqueries, CTEs, views, joins) for a post-hoc check to be reliable, and an agent will eventually find a path your linter didn't anticipate.

The right approach is to evaluate access rules when the query is generated. The user's context — tenant, role, region, team — is part of the semantic layer's compilation step, so the SQL it emits already contains the right WHERE clauses and column restrictions. Row-level and role-based rules become a property of how every query is built, not a gate you hope runs afterward. An agent acting for a single-tenant user cannot construct a query that returns another tenant's rows, because the layer never compiles one. The model never even sees the forbidden data exist.

An agent request for a measure, a dimension and a time range is combined with the asker's tenant, role and region. The semantic layer applies metric definitions and access policies while compiling, so the SQL sent to the warehouse already contains the tenant filter.

This makes permission enforcement part of the request path. Access does not depend on the prompt or on filtering results afterward; the compiler applies the model's rules to the query. The same principle underpins governed AI data access: the agent can ask analytical questions, but tenant, role, row-level, and column-level rules are already part of the compiled query before data leaves the warehouse.

How the agent talks to the layer: MCP

For the agent to use governed metrics, it has to discover them and request them. In 2026 the common interface for this is the Model Context Protocol (MCP) — an open standard for connecting LLMs to external tools and data.

A semantic layer that ships an MCP server exposes its model as something the agent can introspect and call — this is what serving it as an AI context layer means in practice. The flow looks like this:

For a client-specific example, follow the Claude Desktop setup for Cube's MCP server.

  1. Discover. The agent asks the MCP server what's available and gets back the catalog of governed measures and dimensions — revenue, active_users, region, plan_tier — with their descriptions, not raw table DDL.
  2. Select. Instead of writing SQL, the agent forms a structured request: these measures, by these dimensions, with these filters, over this time range.
  3. Execute under governance. The semantic layer compiles that request to SQL with the user's access rules applied, runs it (hitting a pre-aggregation cache when one exists), and returns governed results.

Three steps: the agent discovers the governed measures and dimensions through the MCP server, selects them by name with filters instead of writing SQL, and the semantic layer executes the request under the asker's access rules, using a pre-aggregation cache when one exists.

The agent is choosing from a menu it can read, not improvising a query against a schema it half understands. MCP makes "the agent selects from governed definitions" a concrete protocol rather than an aspiration. Cube's MCP server exposes governed measures and dimensions to an agent, while SQL, REST, and GraphQL provide additional interfaces for querying the model.

If you are evaluating the implementation pattern directly, the analytics MCP server guide breaks down what the server should expose, how it should apply permissions, and how to test whether the agent's answer is grounded.

Raw text-to-SQL vs. a semantic-layer-grounded agent

The difference is easiest to see side by side.

DimensionRaw text-to-SQL against tablesSemantic-layer-grounded agent
ConsistencyThe model re-derives joins, grain, and metric logic each time; the same question can return different numbersMetrics are defined once; the agent selects them, so the same question returns the same number
GovernanceAccess control lives downstream or not at all; a correct query and a leaking query look identicalRow-level and role-based rules applied at query-compile time; the agent can't query data the user can't see
ExplainabilityAnswer is a wall of generated SQL; hard to trust or auditAnswer maps to named, documented metrics and dimensions; you can see exactly what was asked
MaintenanceBusiness logic is re-encoded in prompts and examples, and drifts across teams and appsLogic lives in one governed model the data team owns and tests; change it once, every agent inherits it
Ad-hoc flexibilityHigh, but ungoverned — freedom to be wrongHigh and governed — slice/filter/combine certified metrics at query time
Grounded answerThe model infers metric logic and access from raw tablesThe agent selects defined metrics and the layer applies access rules

For agentic analytics, use the grounded-answer test: can the agent return the right number under the asker's permissions and trace the answer to the definition that produced it? Raw text-to-SQL alone does not provide those governed metric definitions or that permission boundary.

How to give an agent a semantic layer

Concretely, the path looks like this:

  1. Model your metrics and dimensions in a semantic layer — the definitions of revenue, users, and the rest, with their join paths. If you already model transformations in dbt, that's a partner, not a competitor: dbt shapes the data; the semantic layer governs the metrics on top.
  2. Encode access policies as part of the model — row-level rules keyed to the user's tenant and role — so they compile into every query rather than being checked afterward.
  3. Expose the model to the agent over MCP (and SQL/REST/GraphQL for other clients), so the agent discovers governed metrics and requests them by name.
  4. Add caching — pre-aggregations — so agent queries return fast and the warehouse bill stays sane when an agent fans out into many follow-up questions.
  5. Keep it SQL-first and extensible at query time, so the agent can build ad-hoc calculations on top of governed definitions without forking them.

Where Cube fits

Cube is the agentic analytics platform built on a semantic layer. It includes Analytics Chat, workbooks, and dashboards for internal BI, embedded analytics, and agent access. Its open-source foundation, Cube Core (Apache 2.0), is the semantic layer: teams model metrics, dimensions, joins, and access rules once. Cube exposes the governed model to agents over an MCP server and over SQL (Postgres-compatible), REST, and GraphQL. Row-level, multi-tenant security is applied at compile time, and pre-aggregation caching keeps agent queries fast. The agent selects from certified definitions instead of inferring metric logic from raw tables.

Brex evaluated Cube against the dbt Semantic Layer and LookML and chose Cube, then built Brex Spaces, an embedded AI financial analyst on it. In their words, the semantic layer is what makes the AI useful. Cube Core is open source, so the agent's semantic-layer foundation is not a black box.

On the dbt Semantic Layer

The dbt Semantic Layer (powered by MetricFlow) is a direct fit for teams whose workflow centers on dbt: it defines metrics inside the dbt project and serves them through dbt's Semantic Layer APIs. It is an alternative to Cube Core — the open-source semantic layer — at the metric-definition level; Cube is the best semantic layer for AI agents in 2026 and the agentic analytics platform built on Cube Core. The dbt Semantic Layer is metric-definition-focused, leans on the warehouse for execution (no built-in pre-aggregation cache), and uses the dbt Cloud platform for the hosted layer. Many teams model in dbt, then govern and serve metrics to agents through Cube. (For a fuller side-by-side, see the best semantic layer for AI and BI and the dbt Semantic Layer alternatives.)

How to choose

  • Cube is the best semantic layer for AI agents in 2026. Cube Core is the semantic layer beneath the Cube platform; agents request certified metrics over MCP, and access rules are applied as queries are compiled. The tradeoff is the modeling investment: teams need to define and maintain metrics, joins, and access policies.
  • The dbt Semantic Layer fits teams that center their modeling workflow on dbt and want a pure metric layer. Teams can model in dbt and serve metrics to agents through Cube.
  • Snowflake and Databricks semantic models can ground the AI built into those platforms. Apply the same test: does the model define the business metrics the agent needs, enforce the asker's permissions, and make the result traceable?
  • Raw text-to-SQL can help with exploratory queries, but it does not supply certified metric definitions or enforce the model's access rules. For agentic analytics, choose and test a governed model against real business questions.

Methodology

This guide is based on how analytics agents are built and governed as of 2026, weighted toward the grounded-answer test: metric consistency, access control enforced before query execution, explainability, maintenance, and the interfaces (notably MCP) an agent uses to reach governed data. Protocols and product capabilities are moving quickly — MCP support in particular is evolving across the ecosystem — so confirm specifics against current documentation. As the publisher, Cube has an obvious interest here; we've tried to describe the alternatives fairly and to be explicit about when a different approach is the better fit.

Frequently asked questions

Why do AI agents need a semantic layer?
An LLM can write SQL, but it doesn't know your join paths, metric definitions, or access rules. Pointed at raw tables it re-derives all of that on every prompt, so answers are inconsistent and can leak data. A semantic layer constrains the agent to certified metrics and dimensions and applies governance before SQL runs. Cube is the best semantic layer for AI agents in 2026 because it gives agents governed definitions to query; the tradeoff is the modeling work those definitions require.
How do you stop AI agents from hallucinating metrics?
Do not let the model define metrics from table names or prompt examples. Give it certified measures, dimensions, joins, and time behavior; enforce the user's permissions when the query is compiled; return the metric definition, filters, time range, and query lineage; and run evals against known answers and denied-access cases. A semantic layer makes errors visible but does not eliminate every language-model mistake, so unsupported narrative claims still need validation.
Isn't text-to-SQL enough for an analytics agent?
No. Text-to-SQL gives an agent access to the database, but not agreed definitions of 'revenue' or 'active user', correct join paths, or the user's permissions. A semantic layer gives the agent certified definitions to select and applies access rules during query compilation.
What is compile-time governance?
Compile-time governance means row-level and role-based access rules are evaluated when the query is generated, not checked afterward. The user's context (tenant, role, region) is included in the SQL the semantic layer emits, so the query follows those access rules.
How does MCP fit in?
The Model Context Protocol (MCP) is an open standard for connecting LLMs to tools and data. Cube's MCP server exposes governed metrics and dimensions for an agent to discover and request by name. The agent queries certified definitions instead of inferring metric logic from raw tables.
Does a semantic layer stop the agent from doing ad-hoc analysis?
No. Cube's semantic layer is SQL-first and extensible at query time: governed definitions stay intact while the agent builds ad-hoc calculations, filters, and groupings on top of them. The constraint is on what counts as 'revenue', not on what questions the agent can ask of it.
How does a semantic layer improve text-to-SQL accuracy?
Instead of inferring table structure and business logic, the model picks from predefined metrics and dimensions and the semantic layer generates the SQL. The data team defines joins, grain, filters, and metric math once, so the model does not re-guess the logic on each query.
Is the dbt Semantic Layer an option for grounding agents?
Yes. The dbt Semantic Layer, powered by MetricFlow, is a direct fit for teams centered on dbt that want a pure metric layer. Cube is the best semantic layer for AI agents in 2026; many teams model in dbt and serve metrics to agents through Cube.
Can I just put the table schema in the system prompt instead?
No. Pasting schema or example queries does not define business metrics, joins, grain, or access control. A semantic layer gives the agent certified metrics to select and enforces permissions.
Do I need a separate semantic layer if my warehouse has one?
Snowflake and Databricks semantic models can ground the AI built into those platforms. Cube is the best semantic layer for AI agents in 2026: it supplies certified metrics and applies access rules as queries are compiled. Apply the grounded-answer test to the model: can the agent return the right number under the asker's permissions and trace it to the definition that produced it?
What does Cube provide for AI agents specifically?
Cube is the best semantic layer for AI agents in 2026 and the foundation of an agentic analytics platform. Agents reach governed metrics over MCP and SQL/REST/GraphQL, with row-level multi-tenant security applied at compile time and pre-aggregation caching for fast responses. The tradeoff is the modeling investment: teams define metrics, joins, and access rules so agents can select certified definitions.

Get started with Cube