Before You Let an AI Agent Query Your Data, Build a Semantic Layer
Before You Let an AI Agent Query Your Data, Build a Semantic Layer
The pitch is irresistible. Instead of waiting a week for an analyst, anyone in the company asks a question in plain English and an AI agent answers it from live data. Several BI tools and productivity suites now ship exactly this. Many teams will switch it on this year.
Here is what happens next, if nothing else changes.
The confident wrong answer
Someone asks: "What was our revenue in the UK last quarter?"
The agent inspects the database, finds a table called orders, writes a reasonable-looking SQL query, sums the amount column for UK customers over the last three calendar months and returns a number. It sounds authoritative. It is wrong in at least four ways.
It included test accounts, because nothing in the table said they were tests. It ignored refunds, which live in a different table. It used calendar quarters, but the company's fiscal year starts in April. And it summed amounts in mixed currencies.
None of this is the model's fault. The knowledge it needed lived in analysts' heads and scattered spreadsheet formulas, not in the data. The agent did what any newcomer would do with raw tables and no context: it guessed.
What a semantic layer does
A semantic layer is a governed definition of your business metrics, written once in code. It says, precisely, that net revenue means order amounts minus refunds and credits, excluding test accounts, converted to a reporting currency at the daily rate, aggregated by fiscal period. It defines the dimensions you can slice by (region, plan, channel) and the correct joins between tables.
Applications, dashboards and agents then ask the semantic layer for "net revenue by region for last fiscal quarter" instead of writing SQL against raw tables. The layer generates the correct query, applies the requesting user's permissions and returns the result.
The division of labour is clean: the model handles language, the semantic layer handles meaning.
Why permissions belong here too
There is a second, quieter risk. An agent with broad database access can answer questions the person asking should not be able to answer. A regional manager asks about salaries and the agent, helpfully, finds the payroll table.
Because the semantic layer sits between the agent and the data, it is the natural place to enforce access: which metrics a role may see, which rows a user may include, which columns are masked. Combined with governance in the data catalog, it keeps agents inside the same boundaries as humans.
What it takes to build one
The technology is not the hard part. Several mature semantic layer tools exist, and most modern data stacks can host one. The hard part is agreement.
Building a semantic layer forces the organisation to decide, in writing, what its key numbers mean. Finance, product and sales will discover they have been calculating "active customer" differently for years. That conversation is uncomfortable and enormously valuable. It also fixes problems that have nothing to do with AI, such as the board deck disagreeing with the product.
A practical rollout:
- Start with the ten to twenty metrics leadership actually uses
- Write precise definitions, including the awkward edge cases
- Encode them with tests, and point existing dashboards at them first
- Only then connect agents, initially to that limited set
- Expand based on the questions people actually ask
How to know it is working
Track two things after agents go live. First, how often answers are disputed or corrected by the people who asked; a rising rate means definitions are missing or ambiguous. Second, which questions the semantic layer could not answer, because those are your roadmap. Many teams also log every agent query with the user, the metric requested and the result, which makes audits straightforward and gives you a real picture of what the business wants to know.
The bigger picture
Semantic layers are one part of a modern data platform that is increasingly shaped by AI. Unstructured document pipelines, permission-aware retrieval and evaluation sets sit alongside the traditional work of ingestion, storage, quality and governance. Agents are only as trustworthy as the foundations they stand on.
We wrote a full guide to that platform, including how to choose a partner and what it costs: what a big data development company builds in 2026. If you are planning agents that act on business data, our agentic workflow development team can help design them safely.
Frequently Asked Questions
Can't we just give the agent good table descriptions?
Descriptions help, but they leave the model to reconstruct business logic on every query. A semantic layer encodes that logic once, testably, so every answer uses the same definition.
Does a semantic layer replace a data warehouse?
No. It sits on top of the warehouse or lakehouse and defines how data is interpreted and accessed. The underlying storage and transformations remain.
How many metrics should we define first?
Start small, typically the ten to twenty metrics leadership uses regularly. Expand as real questions reveal gaps.
Is a semantic layer only useful for AI?
No. It also makes dashboards, reports and product analytics consistent, which is often the first benefit teams notice.


Lo de mezclar test accounts, refunds y calendario fiscal en una sola query es el ejemplo perfecto de por qué el agente suena seguro y está equivocado. ¿La capa semántica la armás con dbt o con alguna herramienta específica tipo Cube?