Request a demo
← All articles
Governance

Row scope, masking and tenancy for agent context

Whose rows an agent sees should come from who is asking, never from what the request says. How contexts apply scope, mask personal data and stay tenant-safe.

· 7 min read · For heads of data governance, security and AI platform

The first question a security team asks about an AI agent is not "how smart is it" but "what can it see". For structured data the honest answer is usually "whatever the service account it runs under can see", which is far more than any one person should. A context layer changes that answer to "exactly what the person behind it is entitled to, with personal data masked unless they are cleared".

This post explains how InsightCompose contexts enforce three things on every call: row scope (whose rows), masking (which values) and tenancy (which organization). It is part of our context management series.

The rule: scope comes from the caller

The single most important design decision in the context layer is this: the rows a caller gets are decided by who the caller is, never by anything in the request. There is no owner_id parameter to pass, forget or forge. An agent cannot be talked into asking for another person's book, because the request has nowhere to say it.

Scope comes from the caller, not the requestThe request names a context and its parameters. Whose rows come back is decided by the authenticated caller, applied by the layer around the template, before the warehouse sees the query.Requestcontext keyparametersAuthenticated callerkey or sign-inbook, organization, rolesscope comes from hereContext templateSQL with :params+ owner / org filterwrapped around itWarehouseread-onlytimeoutrow capMasked resultpersonal columnsmasked unlesscleared+ audit row
The request names a context and its parameters. Whose rows come back is decided by the authenticated caller, applied by the layer around the template, before the warehouse sees the query.

When a call arrives, the product resolves the caller: an API key, a signed-in person, or an agent acting for a person. From that it knows the caller's book (the owners whose rows they may see, which may be their own, their team's or all), their organization and their roles. The layer then wraps the scope around the context's SQL. The template returns detail rows that carry the scope columns, and the layer keeps only the rows the caller is entitled to.

Three ways to scope, and no fourth

Every context has to say how its rows are scoped. There are exactly three answers:

  • By owner. owner_column names the output column that holds the book owner: an account executive, an underwriter, a branch. A caller sees rows for the owners in their book.
  • By organization. org_column names the column that holds the tenant. A caller sees rows for their organization only.
  • Public. public: true declares reference data that every signed-in caller may read, such as a list of product lines.

A context that says none of these does not validate, so it cannot be published. Unscoped is something you have to say out loud, never something you get by forgetting.

Totals after scope, not before. A rollup, such as "premium by line", is computed after scope is applied. An administrator sees one row per line across the whole business; an account executive sees one row per line across their own book. The same context, the same definition, the right totals for each caller.

Masking personal data

Scope decides which rows. Masking decides which values in those rows a caller may see in clear. Each context declares a personal-data level and, for each sensitive column, a masking rule.

LevelMeaningWhat the layer requires
noneNo personal or internal dataNothing extra
internalBusiness data, not personalA signed-in caller
personalContains personal dataMasking rules on the personal columns
sensitiveSpecial categories or high-risk fieldsNamed roles allowed to call it at all

Four masking rules cover nearly every case:

Masking rules applied per columnEach personal column declares a rule. Callers with a clearance role see the value; everyone else sees it redacted, hashed, cut to the last four characters, or null.One row, two callerscolumncleared callerruleeveryone elsepolicyholderA. Riveraredact••••••emaila.rivera@example.comhash7f3a…c91eaccount_no4402 1187 3350last4… 3350date_of_birth1984-03-12nullnull
Each personal column declares a rule. Callers with a clearance role see the value; everyone else sees it redacted, hashed, cut to the last four characters, or null.
  • redact replaces the value entirely. Use it for names and free text.
  • hash replaces the value with a stable hash, so a consumer can still count distinct customers or join two answers without seeing who they are.
  • last4 keeps the last four characters, which is enough for a person to confirm an account number on a call.
  • null removes the value, for fields a caller has no reason to know at all.

Callers with one of the context's clearance roles see the values in clear. Everyone else sees them masked. The response says whether masking applied, so a consumer can tell "this field is empty" from "you are not cleared to see it". A context marked sensitive must also name the roles allowed to call it; there is no sensitive context that anyone can call by default.

Why masking belongs in the layer, not the agent

It is tempting to tell an agent "do not reveal personal data" in its instructions. That is a request, not a control. A model can be prompted around it, and it has already seen the data by the time it decides. Masking in the context layer means the value never reaches the agent in the first place. For agents connected over MCP, results are also passed through redaction and a size cap before they leave the server.

Tenancy

Many organizations run one platform for several business units, subsidiaries or, for software companies, customers. Tenancy is scope at the organization level, and it follows the same rule: the organization comes from the caller's identity, never from the request.

Tenancy shows up in three places:

  • Rows. Contexts with an org_column return only the caller's organization's rows.
  • Sources. A tenant can be bound to its own source connection, so its contexts run against its own database or schema.
  • Caches. A cached answer is keyed by the caller's scope, the organization and whether masking applied. Two callers who would get different rows never share a cache entry, so a cache can never leak one tenant's answer to another.

Failing closed

Every control above fails closed. If a caller cannot be resolved, the call is refused. If a caller's book is empty, they get no rows, not all rows. If a context's scope column is missing from the output, the call fails rather than returning unscoped data. If a parameter is not declared, it is refused. If the statement is anything other than one read-only query over the allowed schemas, it does not run.

Refusals are never cached, so a fix takes effect on the next call. And every refusal is recorded, which brings us to audit.

Audit with hashed values

Every call writes one row to the audit log: who called, which context and version, the parameter names that were given, a hash of the resolved values, the status, rows returned and timing. The values themselves are not stored. Equal calls hash equal, so you can count how often the same question is asked without keeping what was asked.

That shape answers the questions a governance team actually asks:

  • Which agents and applications call this context, and how often?
  • Who was refused, and why?
  • Did anyone call the sensitive context outside the roles we expected?
  • Which version were they on when the definition changed?

The catalog shows the same data per context: calls, failures, distinct callers, median latency and the last call. See governance and security for the full set of controls.

Putting it together

Consider a fictional underwriting book. An underwriter's assistant asks for "my open submissions this week". The context's SQL is the same for every underwriter. The layer resolves the caller to one underwriter's book in one organization, wraps that scope around the template, binds the date window, runs it read-only with a timeout and a row cap, masks the broker contact's email with a hash because the underwriter lacks the clearance role, stamps the answer with as_of, and writes an audit row. The assistant gets exactly what that underwriter may see, and nothing it could leak.

Ask the same context as an underwriting manager and the book widens to the team; ask as a compliance officer with clearance and the email appears in clear. Same context, same definition, different callers, different answers, all correct.

Where people stay in charge

People decide whose rows each caller may see, by managing books, organizations and roles in the identity systems they already run. People decide which columns are personal, how each is masked and which roles are cleared to see them. Agents never choose their own scope, never unmask a column and never see a value they are not entitled to. The audit log gives a person the full record of who asked what, so any surprise can be traced and any entitlement tightened.

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.