Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Sanity is a structured content platform: teams define content schemas in Sanity Studio and manage records in Content Lake. Its query and access controls can limit which catalog records an AI agent can see, while schema-aware tools can constrain the structure of documents it creates. Those controls do not by themselves prove that a recommendation is suitable, fair, eligible, or compliant with business policy. For that, the application must apply and test explicit rules before showing or saving recommendations.

What Sanity does

Sanity separates structured content from the interfaces and applications that use it. Teams define schemas and manage content in Sanity Studio; records are stored in Content Lake. GROQ, Sanity’s query language, can filter documents, follow references to related documents, and project selected fields into a result. That makes a structured product catalog usable as source material for a recommendation workflow.

Sanity Context is a hosted Model Context Protocol (MCP) server that gives AI agents structured, read-only access to selected content. It does not run the model or the agent loop: developers supply the model, API key, and harness. Context offers two modes: GROQ mode queries a live dataset at request time, while Knowledge Base mode serves material indexed ahead of time. GROQ is a better fit when recommendations depend on current structured fields; an indexed knowledge base fits material spread across prose sources.

Which controls can constrain an AI recommendation?

1. Put eligibility inputs in structured fields

Represent business criteria as fields the application can evaluate—for example, publication status, category, intended audience, or inventory state. These are design choices, not fields Sanity automatically supplies. Give each field a defined meaning and make the application’s eligibility rules explicit.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

2. Restrict the agent’s source

Configure the Context MCP sources and a server-side GROQ filter so the agent can read only records intended for the workflow. Sanity describes the server-side filter as a hard boundary: a filter supplied by the caller can narrow that scope, but cannot broaden it. Treat this as a retrieval boundary, not a substitute for checking whether a product is appropriate for a particular person.

3. Return only the data the workflow needs

Use GROQ to select eligible documents and project only the fields needed for recommendation. Sanity’s GROQ reference notes that * returns documents the current user can read, so permissions matter as well as the query. Access control limits visibility; it does not establish that a visible record is eligible or suitable.

4. Validate document shape, then check meaning separately

Agent Actions let developers run schema-aware AI instructions that create or modify Sanity documents. A schema can require a field or restrict its type, which helps catch malformed output. It cannot prove that a field’s value is true or that a selected item complies with business rules. Agent Actions are experimental, and their APIs may change.

5. Constrain instructions and field access

AI Assist supports instructions aimed at documents or fields, schema context, explicit inclusion of field content, and a choice of allowed fields. Roles and content resources can limit who creates instructions and which documents they can access. These controls shape the instruction and access surface; they are not semantic verification of the result.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

6. Review the complete authorization path

Sanity roles are additive. A broader grant from another role or a general dataset scope can outweigh the practical effect of a narrower restriction. Public datasets also expose published content to project members. Review role grants, dataset visibility, token handling, Context sources, and filters together rather than assuming one narrow setting defines the final boundary. See Sanity’s content access and security guidance.

What “enforce rules” means—and what it does not

Sanity can help enforce access boundaries and structural constraints: permissions govern access, GROQ filters and projections shape retrieval, AI Assist can limit fields, and Agent Actions are schema-aware. None is an end-to-end recommendation policy engine. A readable product record is not automatically appropriate for a particular user, and a valid document is not necessarily a truthful or compliant one.

Put semantic checks in application logic. A robust flow should apply explicit eligibility predicates before ranking, validate model-selected item IDs against the eligible result set, and re-check important conditions before display or write. Keep enough provenance to identify which catalog records and policy version informed a recommendation. These are implementation practices, not mechanisms Sanity automatically provides.

Choose a mode and meet its setup requirements

Approach When it fits Data behavior
Context in GROQ mode Recommendations rely on structured catalog fields that can be queried. Queries the live dataset at request time.
Context in Knowledge Base mode Recommendations draw on material distributed across prose sources. Serves a knowledge index built ahead of time.

The choice is principally about the shape and freshness of the source material. A live structured catalog can reflect current field values at query time; an index built ahead of time is not the same as a live GROQ query.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Context setup: Sanity lists an organization-level API token with Context Viewer permission, a model and API key, and, for GROQ mode, a Sanity project, Studio 5.1.0 or later for server-side schema support, and a deployed schema. Keep the token server-side. Sanity says a project token is refused for Context authentication regardless of its project permissions.
  • Agent Actions setup: The documented current feature set requires an execution environment, @sanity/client 7.4.0 or later, and API version vX. Generate, Transform, and Translate are available from 7.1.0; Prompt and Patch require 7.4.0. Because the feature is experimental, verify package and API requirements when implementing.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

A practical boundary for a recommendation system

  1. Define policy: specify eligibility, exclusions, and any audience-specific constraints in application logic, using documented catalog fields.
  2. Limit retrieval: configure Context sources and server-side filters; grant only the access required for the workflow.
  3. Retrieve a minimal candidate set: use GROQ filters and projections to supply only eligible records and necessary fields.
  4. Generate and validate: have the model select from those candidates, then verify every selected ID against the eligible set and validate any document shape against the schema.
  5. Re-check before use: re-evaluate critical conditions before displaying a recommendation or persisting a change, and retain provenance for review.
  6. Test authorization end to end: check additive role grants, dataset visibility, token scope, and filters under the actual runtime identity.

Sanity’s documentation does not establish a quantified recommendation-quality, fairness, conversion, or latency result. The platform supplies content, query, and access primitives; recommendation outcomes depend on the model and the application’s policy and validation logic.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.