Part of
Enterprise context layer
Architecture

Context Layer vs Semantic Layer: What AI Agents Need From Your Data

A four-layer stack from AI agent down to the warehouse, with the context layer highlighted above the semantic layer.

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.

What is a semantic layer?

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.

What is a context layer for AI agents?

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.

Why do AI agents need a context layer?

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.

Context layer vs semantic layer: what is the difference?

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.

LayerAnswersBuilt fromAccess checkTypical failure
Semantic layerWhat a number means and how to compute itMetric, dimension and join definitions over the warehouseWarehouse and object permissionsA metric nobody defined, so the question falls back to raw SQL
Context layerWhat this agent may read for this task, and why things happenedA knowledge graph of records, decisions and rules, kept current from source systemsRole checked before retrieval, every retrieval loggedA source that was never connected, so the agent lacks the decision history
Vector retrieval (RAG)Which passages sound like the questionText chunks as embeddings, re-indexed in batchesOften filtered after retrievalSimilar-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.

Route the request
Which layer answers this?
Net revenue by region, last quarter
Semantic layerWhat the numbers mean
Context layerWhat this agent may read
Finds the metric net_revenue and the dimension region
Compiles the governed SQL, joins and filters included
Returns the number, and the model writes the sentence around it
Without the semantic layerThe model writes its own SQL from table names, picks gross where finance means net, and a fan-out join can count each order twice.
Why was this refund escalated last spring?
Semantic layerWhat the numbers mean
Context layerWhat this agent may read
Checks the support role before anything is retrieved
Links the ticket, the Slack thread and the decision behind it
Sends a compact, logged package over MCP
Without the context layerSimilarity search returns tickets that sound alike, the decision history never arrives, and the agent fills the gap with a guess.
Draft a renewal offer for this account under our discount rules
Semantic layerWhat the numbers mean
Context layerWhat this agent may read
Context layer checks the account team role and pulls history and the discount rules
Semantic layer returns the account's usage and contract value from governed metrics
The agent drafts with both, and a person approves before it goes out
Without both layersThe draft quotes a usage figure nobody in finance would recognise, or applies a discount the rules do not allow.
A support agent asks for the payroll ledger
Semantic layerWhat the numbers mean
Context layerWhat this agent may read
Checks the support role before retrieval
Payroll is outside the role, so nothing is fetched
The refusal is logged with the agent, the source and the reason
Without the context layerIf permissions are filtered after retrieval, the restricted rows have already entered the prompt.
Illustrative requests. The steps follow how semantic layers compile metrics and how our context layer checks the role before retrieval.

Do AI agents need both layers?

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.

How to give AI agents a semantic layer and a context layer

  1. List the questions and actions. Write down what the agent will be asked and what it may do, then mark each as a number, a record or both.
  2. Define the metrics the agent will quote. Start with the ten or twenty numbers people already argue about, in the semantic layer your warehouse already supports, and test each against the figure finance signs off.
  3. Map who may see what. Take the permissions from the source systems, so the agent inherits each user's access instead of a shared service account.
  4. Connect the record sources. Ticketing, chat, documents and the CRM, with the decisions linked to the records they explain, as our context layer blueprint lays out.
  5. Write the business rules down. Discount limits, approval thresholds and escalation paths belong in the layer, where every agent reads them, as covered in mapping business rules into the context layer.
  6. Log every retrieval and every answer. Record which agent read what, from which source, and what it produced, so a wrong answer can be traced to its cause.

Frequently asked questions

What is the difference between a context layer and a semantic layer?

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.

Can AI agents use a semantic layer directly?

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.

Is a context layer the same as RAG?

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.

What is the difference between text-to-SQL and a semantic-layer analytics assistant?

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.

Should we build a context layer or buy one?

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.

More on this topic

Put your first workflow on the board

Answer a few questions about your team and what you want automated, then a senior partner scopes it with you on the call.