Request a demo
← All articles
Context

Designing parameterised contexts

Parameters, filters, defaults, allowed values and example phrasings: how to design a context an agent can call correctly the first time, and safely every time.

· 8 min read · For data engineers and analytics leads

A context is only as useful as the questions it can answer without a person rewriting it. Too rigid, and every variation of a question needs a new context. Too loose, and an agent can pass something nobody anticipated. The parameter contract is where that balance is struck, and it is worth designing deliberately.

This is the second post in our context management series. It covers how InsightCompose contexts declare their parameters, how values reach the warehouse, how defaults and allowed values make a context safe for an agent to call, and how example phrasings let an assistant find the right context in the first place.

Start from the question, not the table

Good contexts are named after a question someone asks, not after the table they read. "Open opportunities in a region, by stage" is a context. "The opportunities table" is not. The question tells you which inputs are genuinely variable, which are fixed by the definition, and which belong to the caller rather than the request.

Take a fictional regional sales book. The question "what is open in my territory over the last N days, by stage" has three kinds of input:

  • Variable by request: the window in days, perhaps a product line. These are parameters.
  • Fixed by definition: what "open" means (a set of stage codes), which currency, which pipeline. These live in the SQL and never become parameters, so an agent cannot redefine them.
  • Determined by the caller: whose territory. This is row scope, applied from the caller's identity. It is never a parameter. We cover it in scope, masking and tenancy.

Getting that split right is most of the design work. The common mistake is to make the third kind a parameter, such as owner_id, because it is convenient in a demo. In production it means any caller can ask for anyone's book.

Declaring parameters

Each parameter is declared with a name, a type and the rules that bound it. The types are deliberately few: string, integer, number, boolean, date, timestamp and enum. The SQL refers to each by a :name placeholder, and a context will not publish if the SQL uses a placeholder that is not declared or declares one the SQL never uses.

{
  "key": "sales.book.open_by_stage",
  "title": "Open opportunities by stage",
  "sql": "SELECT stage, owner_name, region, SUM(amount) AS open_amount, COUNT(*) AS deals
          FROM sales.opportunities
          WHERE status IN ('open','negotiating')
            AND created_at >= CURRENT_DATE - :days
            AND (:product_line = 'ALL' OR product_line = :product_line)
          GROUP BY stage, owner_name, region",
  "params": [
    {"name": "days", "type": "integer", "default": 30, "min": 1, "max": 365,
      "label": "Window (days)"},
    {"name": "product_line", "type": "enum", "default": "ALL",
      "values": ["ALL", "hardware", "services", "subscriptions"]}
  ],
  "row_scope": {"owner_column": "owner_name"},
  "questions": ["what is open in my book", "open pipeline by stage",
                "how much is in negotiation this month"]
}

Read the declaration as a promise to every consumer: this context takes a window between 1 and 365 days, defaulting to 30, and one of four product lines, defaulting to all. Anything else is refused.

Defaults make a context callable

A parameter with a sensible default lets a context answer the plain version of its question with no input at all. That matters more for agents than for people, because a context that can run with no input is one an assistant can match to a question directly. Required parameters without defaults are right when there is no sensible answer without them, for example a specific account. Use them sparingly.

Allowed values beat free text

Wherever the set of valid inputs is known, declare it as an enum. The agent sees the list and picks from it; a typo or an invented value is refused rather than returning an empty result that looks like "nothing open". Enums are also how a caller chooses between columns or sort orders safely: the request picks a declared value, and the SQL maps that value to an identifier it already contains.

Bounds stop expensive accidents

A window of 36,500 days is a valid integer and a very expensive query. min and max on numbers and dates keep requests inside what the context was designed and tested for. Together with the statement timeout and the row cap set on every context, they bound the cost of any single call.

Multi-valued parameters

Some filters naturally take several values: three regions, two product lines. Declaring a parameter as multi lets a caller pass a list, which is validated item by item and bound as a list of literals. It is far safer than accepting a comma-separated string and splitting it inside the SQL.

How a value reaches the SQL

The safety rule behind all of this fits in one sentence: values can be parameters; identifiers cannot. A caller-supplied value is rendered as a typed literal. A caller-supplied identifier, whether a column, a table, a sort expression or a function, never reaches the SQL at all.

How a parameter travels from a request to the warehouseEvery value is checked against its declaration, normalized, and bound as a typed literal. A bad value is refused with the name of the field, so an agent can correct itself.Agent requestregion="West"days="30"Validatedeclared names onlytype, bounds, enumdefaults filled inBindvalues as literalsno identifiersre-parse the SQLRun read-onlyscope wrapped ontimeout, row capRefused, with the fieldA value can be a parameter. An identifier never can.
Every value is checked against its declaration, normalized, and bound as a typed literal. A bad value is refused with the name of the field, so an agent can correct itself.

After substitution the statement is parsed again, checked to be a single read-only query over the allowed schemas, and re-rendered from the parsed form. Anything that tried to arrive as syntax rather than as a value does not survive, because the parsed form has nowhere to put it. On engines that offer native bound parameters, values are bound there too.

Validation also normalizes. {"days": 30} and {"days": "30"} become the same resolved question, with defaults filled in. That matters for caching: two callers asking the same question in slightly different shapes share one cached answer instead of waking the warehouse twice. We cover the cache in real-time context.

Refusals are part of the interface. A refused parameter comes back with the field name and a sentence explaining why, such as "days must be between 1 and 365". An agent can read that and retry with a valid value, instead of silently getting an empty answer.

Describing outputs

Parameters describe what goes in; output columns describe what comes back. Each column carries a type, a human label and a unit (money, pct, count, date or text), and a flag if it holds personal data. A consumer does not have to guess that open_amount is a currency value or that win_rate is already a percentage. An agent quoting the figure can format it correctly, and a dashboard tile can draw it without a mapping file.

Example phrasings: how an assistant finds the right context

Once you have more than a handful of contexts, the question becomes which one answers what the person just asked. Each context carries a list of example phrasings, written the way people actually ask: "what's open in my book", "open pipeline by stage". These do two jobs.

Over MCP, they become part of the tool description an agent reads when choosing a tool. Inside InsightCompose's own assistant, they drive a deterministic match that runs before any SQL is written.

Matching a question to a context before writing SQLA context is chosen only when the question is close to one of its phrasings and no other context is equally close. A wrong match is worse than none, because its answer would look governed.Choosing a context for a question“what’s open in my book?”the user's wordsScore each contextagainst its phrasingsand its titlerunnable without input?clear winnertie or low scoreAnswer from the contextFall throughto the guarded SQL engine
A context is chosen only when the question is close to one of its phrasings and no other context is equally close. A wrong match is worse than none, because its answer would look governed.

The match is conservative on purpose. A context is chosen only when the question is close to one of its phrasings (or shares most of its meaningful words with them), only when the context can run without a parameter the question would have to supply, and only when no other context scores almost as well. Two contexts equally close is treated as ambiguity, not an answer. Anything less falls through to the guarded SQL engine, which shows its work.

Writing good phrasings is a small craft:

  • Write three to six, in the words of the people who ask, not the words of the schema.
  • Cover the short form ("open pipeline") and the conversational form ("how much is still open for me this month").
  • Avoid phrasings that would equally fit a neighbouring context. If two contexts keep colliding, they may be one context with a parameter.

A checklist before you publish

CheckWhy
Is the caller's identity a parameter?It should be row scope instead.
Does every parameter have a type and a bound or a value list?Unbounded inputs are unbounded cost.
Can the plain question run with defaults?Agents match contexts that need no input.
Are output columns labelled with units?Consumers should not guess formats.
Are phrasings distinct from neighbours?Ambiguity means no match, by design.
Are the row cap and timeout right for the question?A top-20 list does not need 50,000 rows.

Everything above is visible on the Contexts page in the product, and every published context has a Try it panel that shows exactly what a consumer would send and get back. The full field reference is in the docs.

Where people stay in charge

People decide what a context means: which rows count as open, which values a filter may take, how far back a window may reach. Agents only fill in the blanks those people left open, and only with values the declaration allows. A context does not publish until its parameters match its SQL, and a publish waits for a curator's approval. When an agent's question does not clearly match one context, the system declines to guess, and the gap shows up for a person to decide 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.