Request a demo
← All articles
Context

What a context layer is, and why agents need one

Agents are only as good as the data they are handed. A context layer turns warehouse questions into governed, parameterised, fresh answers any agent can call.

· 8 min read · For heads of data and AI platform leads

Every enterprise AI programme reaches the same moment. The model is capable, the agent framework works, the demo answered a question about last quarter. Then someone asks it about their accounts, as of this morning, without showing the personal data they are not cleared to see, and the room goes quiet. The model was never the hard part. The context was.

A context layer is the part of the stack that decides what data an agent or an application is handed when it asks a question. It sits between your warehouses and every consumer of their answers, and it does one job: turn a business question into a governed, parameterised, scoped, masked and fresh answer that can be called by name. InsightCompose is built around that layer. This post explains what it is, why agents in particular need it, and what it looks like when it is done properly.

The problem agents make worse

Before agents, the number of consumers of a business question was small. A dashboard, a report, perhaps an extract. Each one was built by a person who knew the data, applied the right filters and checked the result. When it was wrong, someone noticed in a meeting.

Agents change the arithmetic. A sales assistant, a service copilot and an operations app all want the same answer to "what is open in my territory", and each will happily write its own SQL to get it. Three implementations of one question means three definitions of "open", three ways of deciding whose rows a person may see, and three places where a personal column might leak. Multiply by every question your business asks, and by every agent your teams will build this year.

Agents wired to databases, versus agents calling contextsOn the left, every consumer re-implements the question, the scope and the masking. On the right, each question is defined once as a context, and every consumer calls it by name.Without a context layerSales agentService copilotOps appDatabricksPostgresSQL Servereach agent writes its own SQL, scope and maskingWith a context layerSales agentService copilotOps appContextsparamsscopemaskingfreshnessauditDatabricksPostgresSQL Serverone governed definition per question, called by name
On the left, every consumer re-implements the question, the scope and the masking. On the right, each question is defined once as a context, and every consumer calls it by name.

Agents also ask more often, and with less supervision. A person reads a figure once and asks a colleague if it looks odd. An agent reads the figure, acts on it and moves on. If the context it was handed was stale, unscoped or computed with the wrong definition, nothing in the loop catches it.

What a context is

In InsightCompose a context is a published, named answer to a question. It is defined once, reviewed, versioned and then served to anything that is entitled to call it. Underneath, it is built from the same contracts that power our data APIs: a read-only SQL statement with typed parameters, plus everything the answer depends on, written down.

The six parts of a contextA context is data, not code: one question, the parameters it takes, whose rows it returns, which columns are masked, how fresh it is, and the shape of what comes back.A published contextQuestionkey, title, example phrasingsParameterstyped :params, defaults, allowed valuesRow scopeowner or organization, from the callerMaskingredact, hash, last4, null per columnFreshnesslive, cached or nightly, SLA, as_ofOutputtyped columns with labels and units
A context is data, not code: one question, the parameters it takes, whose rows it returns, which columns are masked, how fresh it is, and the shape of what comes back.
  • A key and example phrasings. The key is the address, such as sales.book.open_opportunities. It is never reused for a different answer. The phrasings are how an assistant finds the right context before it considers writing SQL of its own.
  • Typed parameters. Region, date window, product line: each declared with a type, a default, bounds or allowed values. Values are bound, never spliced into the statement. Identifiers never come from a request at all.
  • Row scope. Whose rows the caller gets, taken from the caller's identity, never from the request. A context must say how it scopes or declare itself public; there is no silent default.
  • Masking. Which output columns carry personal data, and what a caller without clearance sees instead: redacted, hashed, the last four characters, or null.
  • Freshness. Whether the answer is computed live, served from a cache with a time to live, or built nightly, with the SLA the owner commits to. Every answer carries an as_of timestamp.
  • Typed output. The columns that come back, with labels and units, so a consumer knows that amount is money and win_rate is a percentage without guessing.

None of this is new to a good data team. What is new is writing it down in one place, in a form a machine enforces on every call, so that the definition and its safeguards travel with the answer instead of living in a wiki page nobody reads.

Why a semantic model or a vector store is not enough

Teams often reach for one of two things they already have. A semantic layer defines metrics well, but it answers "how is revenue computed", not "which rows may this caller see, masked how, as of when". A retrieval index gives an agent passages of text, which is the right tool for documents and the wrong one for a figure that has to add up.

A context layer complements both. Your agreed metric definitions and glossary feed into how a context is written; your documents stay in retrieval. The context layer is the part that turns a structured question into a structured answer, under a contract, with a record of who asked.

A useful test. Ask of any number your agent quotes: which definition computed it, whose rows went into it, which columns were hidden, and how old is it? If the system cannot answer all four from the response itself, the number is not yet context. It is just data.

What the layer does on every call

When an agent or application calls a context, the same guarded path runs every time, regardless of who is calling or how:

  1. The caller is identified by key or by sign-in, and the context checks the roles allowed to call it.
  2. Parameters are validated against their declared types, bounds and allowed values. Anything undeclared is refused, not ignored.
  3. The caller's scope is wrapped around the statement: their book of business, their organization, or nothing if the context is public.
  4. The statement is checked to be a single read-only query over allowed schemas, then run with bound values, a statement timeout and a row cap.
  5. Masked columns are masked for callers without clearance.
  6. The result comes back with typed columns, as_of, the freshness promise, whether it was truncated and whether masking applied.
  7. The call is written to the audit log: who, which context and version, a hash of the values, rows returned and timing.

No model runs in that path. The model's job is to pick the right context and fill in its parameters. The layer's job is to make sure that whatever the model picks, the answer is safe and correct for the person behind it.

Why agents need it more than people do

Three properties of agents make a context layer necessary rather than nice to have.

Agents cannot be trusted with identity

An agent passes along whatever it is told. If row scope came from a request parameter, a prompt injection or a confused tool call could ask for someone else's rows. Because scope comes from the authenticated caller and is applied by the layer, there is nothing in the request for an agent to get wrong.

Agents need a menu, not a schema

Handing an agent your whole schema and asking it to write SQL works in a demo and drifts in production. Handing it a short list of named contexts, each with a description, typed parameters and example phrasings, turns an open-ended generation problem into a selection problem. Selection is something models do reliably, and something you can test.

Agents act on freshness they cannot see

A person notices that a report says "as of last Friday". An agent does not, unless the answer tells it. Every context response carries as_of and the freshness promise, so an agent can say "as of 09:40 today" in its reply, or decide to ask for a live refresh when the question needs one. We cover the mechanics in real-time context.

One context, many consumers

The payoff of defining a question once is that every consumer gets the same answer. The same context serves a REST call from your application, a tool call from an agent connected over MCP, and a tile on a dashboard. Change the definition and every consumer moves together, at a new version, with the old one still available to callers who pinned it. We go deeper in one context, many consumers.

ConsumerHow it calls a contextWhat it gets
Your applicationREST, with an API keyTyped rows, as_of, freshness, masking flag
An AI agentMCP tool, with a key or OAuthThe same answer, sized for a model's context window
A dashboardThe same contract behind each tileThe same numbers, with lineage on each tile

Where to start

You do not need to model your whole business to get value from a context layer. Start with the five questions your agents and apps ask most often, usually the ones that sound like "what is in my book", "what changed since last week" and "how am I doing against target". Connect the source they live in, whether that is Databricks, Snowflake, Postgres or SQL Server. Let the discovery agent propose what else the data can answer. Write each question as a context with explicit parameters, scope and masking, publish it, and connect one agent to it.

The next posts in this series walk through each part: designing parameters, scope, masking and tenancy and serving context over MCP.

Where people stay in charge

A context layer moves decisions to the people who should own them. A data owner writes and publishes each context; a curator approves the publish; an administrator decides which keys and groups may call it and at what scope. Agents choose among published contexts and fill in parameters, but they never define what a context means, widen whose rows it returns or unmask a column. When an agent's question does not match a context closely enough, the layer says so rather than guessing, and a person decides whether a new context is needed.

See your own context layer, on your data

Bring one source and three questions your agents or apps need answered. We will stand up governed contexts over them in your environment and connect an agent to them in a working session.

We reply within one business day. Next comes a 45-minute executive briefing for your CIO or CDO, then, if it fits, a 12-week Innovation POD in your environment.