
A context layer is the part of your data stack that decides what an AI agent may read for a given task and assembles it, checking the agent's role before retrieval and linking the records, decisions and rules the task needs. A semantic layer defines what your data means: each metric, dimension and join written once, so every query computes revenue or churn the same way. An agent that answers questions about numbers needs the first, an agent that reads and acts on records needs the second, and most enterprise agents end up needing both.
The gap shows up in accuracy before it shows up anywhere else. In a 2023 benchmark on an enterprise insurance schema, Juan Sequeda, Dean Allemang and Bryon Jacob found that GPT-4 answering questions with zero-shot prompts directly over the SQL database was accurate 16% of the time, and 54% of the time when the same questions ran over a knowledge graph that described what the tables meant. A newer model does not supply the meaning your schema leaves out.
A semantic layer sits between your warehouse and whoever asks it a question. Your data team defines each metric once, with its formula, filters, grain and the joins it is allowed to use, and the layer compiles a request such as net revenue by region into the right SQL every time. Dashboards, spreadsheets and agents that go through it get the same answer.
The main data platforms all ship one. dbt Labs offers the dbt Semantic Layer, powered by MetricFlow. Snowflake has semantic views, which hold business concepts, metrics and relationships as schema objects and serve as the business context for Cortex Analyst. Databricks has Unity Catalog metric views, defined in YAML and queried with SQL. Microsoft renamed Power BI datasets to semantic models, the Analysis Services models behind every report.
Agents can now call these layers directly. The dbt MCP server exposes Semantic Layer tools such as list_metrics and query_metrics, and a Snowflake semantic view can be added as a tool on a Cortex Agent. If you are new to the protocol, our explainer on what an MCP server is covers how an agent calls a tool like this.
A context layer serves agents that read records and take actions, where a semantic layer serves questions about numbers. It works on tickets, emails, chat threads, documents, code and the decisions behind them, which rarely fit in a metric definition. Our enterprise context layer has five parts: event-driven ingestion from the systems you run, a knowledge graph that links records with the decisions behind them, contextual sandboxing so each task sees only what it needs, delivery to every agent over MCP, and governance that checks permissions before retrieval and logs every retrieval with the agent, the source and the result.
Two of those parts do most of the work. The graph is what lets an agent answer why something happened as well as what happened, because the ticket arrives with the Slack thread and the decision attached. The permission check before retrieval is what keeps a restricted record out of the prompt altogether, where a filter applied afterwards is too late. Our guide to data governance for AI agents covers that second part in depth.
The discipline of deciding what goes into a model's window for each task is context engineering. The context layer is the infrastructure that does it the same way for every agent.
Without one, each agent builds its own access to company data, and three things go wrong. The agent reads a copy of the data that was indexed last week, so it quotes a status that has since changed. It runs under a shared service account, so a restricted record can reach the prompt of someone who should never see it. And it finds the ticket without the thread that explains it, so it answers what happened and guesses why.
A context layer fixes all three once, for every agent: current data from the source systems, the user's own permissions checked before retrieval, and records linked to the decisions behind them. The second agent you build reads from the same layer as the first, instead of starting its own integrations.
The two layers answer different questions, are built from different material and fail in different ways. A plain retrieval pipeline over a vector database is the third option most teams start with, so it belongs in the comparison.
| Layer | Answers | Built from | Access check | Typical failure |
|---|---|---|---|---|
| Semantic layer | What a number means and how to compute it | Metric, dimension and join definitions over the warehouse | Warehouse and object permissions | A metric nobody defined, so the question falls back to raw SQL |
| Context layer | What this agent may read for this task, and why things happened | A knowledge graph of records, decisions and rules, kept current from source systems | Role checked before retrieval, every retrieval logged | A source that was never connected, so the agent lacks the decision history |
| Vector retrieval (RAG) | Which passages sound like the question | Text chunks as embeddings, re-indexed in batches | Often filtered after retrieval | Similar-sounding but wrong material, or last week's copy of the data |
Pick a request below to see which layer serves it, in what steps, and what goes wrong when that layer is missing.
Most of the agents we build need both, because the task mixes a number with a record. A renewal draft needs the account's contract value from a governed metric and the account's history and discount rules from the context layer. In our builds the agent talks to the context layer, which calls the semantic layer whenever the task needs a number.
Our own builds follow the same split. When we built daily MI alerting for IES Limited, every figure became a PostgreSQL view, n8n read the result and decided who needed to know, and the language model received finished numbers and wrote a sentence around them, so nothing calculates in two places. The IES daily MI alerting case shows the alerts cutting the time to notice a drop in the quote funnel from 20 days to 30 minutes.
Pinkcube's chat agent shows the context side. It answers from a knowledge base built out of Pinkcube's own resolved support conversations, reads live order status from HubSpot and AfterShip for each question, and works under hardcoded business rules, with a second agent checking every draft. The Pinkcube case covers how that agent now answers all 168 hours of the week.
A semantic layer defines metrics, dimensions and joins once so every query computes them the same way. A context layer decides what an agent may read for a task, links records with the decisions and rules behind them, and checks permissions before retrieval.
Yes. The dbt MCP server exposes Semantic Layer tools such as list_metrics and query_metrics, and Snowflake semantic views can be added as tools on Cortex Agents. The agent asks for a governed metric instead of writing its own SQL.
No. A basic RAG pipeline returns text chunks that look similar to the question, usually from a batch-built index with permissions filtered afterwards. A context layer links records in a graph, keeps them current from the source systems and checks the agent's role before anything is retrieved.
A text-to-SQL assistant has the model write SQL against your raw tables, so it has to guess which columns, filters and joins make up a metric. A semantic-layer assistant asks for a defined metric and the layer compiles the SQL, which is how Snowflake's Cortex Analyst uses semantic views as its business context. The second gives the same figure finance signs off; the first gives whatever the model inferred.
Usually some of each. The data platforms ship semantic layers, MCP servers and access controls you can reuse, but which sources to connect, whose permissions apply and which business rules an agent must follow are specific to your company. Build the parts that encode your own rules and permissions, and buy or reuse the plumbing underneath.
If your agents need governed access to company data, see how we build an enterprise context layer inside your own cloud, or book a discovery call and a senior partner will map your sources with you.