CoursesRetrieval methods for AI agentsWho owns the answer
Retrieval methods for AI agents

Who owns the answer

Scope what your agent can reach with Sanity Context, and recognize the answers that shouldn't come from your content at all.
Log in to mark your progress for each Lesson and Task

A customer asks your agent whether their account is past its usage limit, and the agent answers from your pricing content. What went wrong?

The agent answered a question about one account using a document that describes a plan. The plan's limit is 50,000 events, which is true, published, and correctly retrieved. Whether this particular customer has used 51,000 of them is a fact only your billing system holds. The answer was assembled with complete confidence from the wrong owner.

Nothing in the retrieval layer prevents that. There is no built-in router. Every backend you connect contributes its tools to one flat list, and the model chooses by matching tool names and descriptions against the conversation. Sanity Context's tools are deliberately generic. groq_query, schema_explorer, and initial_context describe mechanisms rather than domains, so a model choosing between them and a billing API's tools has very little to go on.

You are the router. An ownership table makes the split visible, with exactly one owner for each kind of data your agent could be asked about.

  • Catalog, articles, help content, and marketing copy. Sanity owns them, because they are structured, editorially managed, and queryable.
  • Live inventory, order status, and shipping. Your commerce platform or order management system owns them, because they change second by second.
  • Payments and refunds. Your billing system owns them as the system of record, and the operations have side effects.
  • Support ticket history. Your helpdesk owns it, because it owns the conversation.
  • Entitlements and current usage. Your billing or entitlement service owns them, because they are per-account state.

Sanity owns your content: the product, the plan, the policy, and every word you have published about them. Operational systems own state: what this customer has used, where that order is, how many units are left. Most routing problems answer themselves once the split is clean, and the table becomes the routing table in your system prompt when you build.

Four ways to enforce the split:

  1. A routing table in the system prompt. Name each data type and the tool that owns it. This isn’t complex, and it handles the ordinary cases.
  2. Structural scoping. A groqFilter on the Context document keeps out-of-scope content from being returned at all, and an instruction stating what the dataset does not contain ("live stock is not stored here, use the inventory tool") closes the gap from the other side. The scoping fails safe, which the prompt alone does not.
  3. Reshaping the tool set. Subset and re-describe the generic tools before handing them to the model, so the description carries the domain and the boundary.
  4. Architectural change. Past a certain complexity, a cheap classification call that picks a domain first, or a supervisor that delegates to sub-agents holding only the relevant tools, scales better than one agent holding every tool.
const tools = {
...commerceTools,
query_content: {
...sanityTools.groq_query,
description:
'Query the CONTENT catalog (products, articles, help docs) in Sanity. ' +
'Use for descriptions, specs, copy, and canonical IDs, NOT live stock or orders.',
},
}

Scoping is the difference between an agent that is asked not to reach something and an agent that cannot. A groqFilter is an access boundary enforced at the endpoint, so excluded content never reaches the model at all. Unreleased work is the clearest case. A plan tier launching next quarter, a feature still in staging, an integration under NDA: all of it sits in your dataset, and none of it should reach a customer-facing agent. A filter like _type == "feature" && status == "ga" keeps it out structurally rather than asking the model not to mention it.

Sanity Context separates what an agent can reach from how it behaves. Scope is the filter. Behavior is the instructions, and they live in Sanity rather than in your agent code, so changing how your agent uses your content takes no deploy and no additional dev work.

Knowledge bases add a review step that isn't possible at query time. A build surfaces contradictions as issues before anything reaches production, a person settles them, and the decision persists as an instruction anchored to its sources. Every entry cites where its claim came from. Query time retrieval still involves judgment about which source to believe. The judgment happens at answer time instead, once per question, with no one to validate.

Composing across owners is how a working agent answers a question like the one that opened this lesson. Resolve the canonical product and its editorial detail from Sanity, hand the SKU to the commerce API for live stock, and answer from both. Because you own the split, you decide what your agent trusts for which class of fact, and no vendor default decides it for you.

You must be logged in to answer questions
A customer asks whether their account is past its usage limit. Which system should answer?
1
The billing or entitlement service that tracks consumption
2
A GROQ query against your plan documents
3
A knowledge base entry describing plan limits
4
The system prompt, if the limits are listed there
You have 1 uncompleted question in this lesson
0 of 1