
A context layer decides what an AI agent may read for each task and gathers it. It checks the agent's role before it fetches anything, and it links each record to the decisions and rules the task needs. A semantic layer defines what your numbers mean. Your data team writes each metric, dimension and join once, so every query calculates revenue or churn the same way. An agent that answers questions about numbers needs a semantic layer. An agent that reads records and acts on them needs a context layer, and most enterprise agents end up needing both.
When an agent does not know what your data means, accuracy suffers first. In a 2023 benchmark on an enterprise insurance database, Juan Sequeda, Dean Allemang and Bryon Jacob asked GPT-4 business questions with no worked examples in the prompt. Querying the SQL database directly, it was accurate 16% of the time. When the same questions ran over a knowledge graph that described what the tables meant, it was accurate 54% of the time. A newer model does not supply the meaning your database leaves out.
A semantic layer sits between your data warehouse and whoever asks it a question. Your data team defines each metric once: its formula, its filters, its level of detail (grain) and the tables it may join. When someone asks for net revenue by region, the layer turns that request into the right SQL every time. Dashboards, spreadsheets and agents that go through it all 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 store business terms, metrics and relationships inside the database. Cortex Analyst, Snowflake's tool for answering business questions about your data, uses them as its business context. Databricks has Unity Catalog metric views, which you define in YAML and query 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 gives an agent Semantic Layer tools such as list_metrics and query_metrics. MCP, the Model Context Protocol, is the open standard AI tools use to connect to company data. In Snowflake, you can add a semantic view as a tool on a Cortex Agent. If you are new to MCP, our explainer on what an MCP server is covers how an agent calls a tool like this.
A semantic layer serves questions about numbers. A context layer serves agents that read records and take actions. 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. It picks up changes from the systems you run as they happen. A knowledge graph links each record to the decisions behind it. A sandbox for each task limits it to the data that task needs. Every agent connects to the layer over MCP. Finally, the layer checks access before it fetches anything and logs which agent read which source, and what came back.
Two of those parts do most of the work. The graph lets an agent answer why something happened as well as what happened, because the ticket comes with its Slack thread and the decision attached. The access check keeps a restricted record out of the agent's prompt entirely. A filter applied after the record is fetched is too late. Our guide to data governance for AI agents covers the access check in depth.
Choosing what a model sees for each task is called context engineering. The context layer is the system that does it the same way for every agent.
Without one, each agent builds its own connection to company data, and three things go wrong. The agent reads last week's copy of the data, so it quotes a status that has since changed. It runs under one shared system account, so a restricted record can reach someone who should never see it. It finds the ticket without the thread that explains it, so it can say what happened but has to guess why.
A context layer fixes all three once, for every agent. It reads current data from the source systems, checks the user's own access before it fetches anything, and links records to the decisions behind them. The second agent you build reads from the same layer as the first, instead of needing its own connections.
The two layers answer different questions, are built from different material and fail in different ways. Most teams start with a third option, a search pipeline over a vector database (RAG, short for retrieval-augmented generation), so the table includes it too.
| Layer | Answers | Built from | Access check | Typical failure |
|---|---|---|---|---|
| Semantic layer | What a number means and how to compute it | Each metric defined once, with its filters and joins, over the warehouse | Warehouse and object permissions | A metric nobody defined, so the model writes its own 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 | Access checked before anything is fetched, and every fetch logged | A source nobody connected, so the agent never sees why a decision was made |
| Vector retrieval (RAG) | Which passages sound like the question | Text chunks stored as embeddings for search, refreshed in batches | Often checked only after the text is fetched | 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. To draft a renewal, the agent needs the account's contract value from a metric defined in the semantic layer. It also needs the account's history and discount rules from the context layer. In our builds, the agent asks the context layer, which calls the semantic layer whenever the task needs a number.
Our own builds follow the same split. For IES Limited we built daily management information (MI) alerts. Every figure became a PostgreSQL view, a saved query in the database. n8n read the result and decided who needed to know. The language model received finished numbers and wrote the sentence around them, so no figure is calculated 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 from support conversations the Pinkcube team had already resolved. For each question it reads live order status from HubSpot and AfterShip. It follows business rules written into its code, and a second agent checks every draft reply. 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 calculates them the same way. A context layer decides what an agent may read for a task. It links records to the decisions and rules behind them, and checks access before it fetches anything.
Yes. The dbt MCP server gives agents Semantic Layer tools such as list_metrics and query_metrics, and you can add Snowflake semantic views as tools on Cortex Agents. The agent asks for a defined metric instead of writing its own SQL.
No. A basic RAG pipeline returns chunks of text that look similar to the question. It usually searches an index rebuilt in batches and checks access only after it fetches the text. A context layer links records in a graph, keeps them current from the source systems and checks the agent's role before it fetches anything.
A text-to-SQL assistant guesses how a metric is calculated, and a semantic-layer assistant uses the definition your data team wrote. With text-to-SQL, the model writes 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 writes the SQL. Snowflake's Cortex Analyst works this way, with semantic views as its business context. The semantic-layer assistant gives the same figure finance signs off, and text-to-SQL gives whatever the model inferred.
Usually some of each. The data platforms already ship semantic layers, MCP servers and access controls you can reuse. Which sources to connect, whose access applies and which business rules an agent must follow are specific to your company. Build the parts that hold your own rules and access settings, and buy or reuse the connectors and tools 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.