RAG & Grounding7 min read·

How to Prevent Confidential Content From Leaking Into RAG Answers

A support agent, asked a routine question about a customer's plan, answers correctly and then keeps going: it surfaces an internal pricing exception, an unredacted contract clause, and a line from an HR document that was never meant to…

A support agent, asked a routine question about a customer's plan, answers correctly and then keeps going: it surfaces an internal pricing exception, an unredacted contract clause, and a line from an HR document that was never meant to leave the building. Nobody prompted for any of it. The retrieval layer simply pulled the nearest-matching chunks, and the model dutifully read them aloud. This is the quiet failure mode of most RAG deployments: leakage happens not because someone attacks the system, but because confidential content sat in the same index as public content and nothing at query time knew the difference.

Sanity Context (previously Agent Context) treats this as a content problem before it is a model problem. Sanity is the AI Content Operating System, an intelligent backend that keeps retrieval, permissions, and governance in the same place your editors already work, rather than bolting access control onto a separate vector store after the fact. The distinction matters because leakage is almost always a gap between where content lives and where its rules live.

This guide walks through why confidential content leaks into RAG answers, the controls that actually stop it, and how grounding agents in structured, permission-aware content closes the gap that ad hoc vector pipelines leave open.

Illustration for How to Prevent Confidential Content From Leaking Into RAG Answers
Illustration for How to Prevent Confidential Content From Leaking Into RAG Answers

Why confidential content ends up in answers nobody asked for

Most leakage is not exotic. The typical RAG pipeline ingests everything it can find, product docs, support tickets, wiki pages, PDFs from a shared drive, and flattens it all into a single embedding index. At that point the content has lost its context. A paragraph from an internal-only runbook and a paragraph from a public help article become two vectors of equal standing, and the retriever ranks them purely on semantic similarity to the query. If the confidential paragraph is the closest match, it wins.

The second failure compounds the first. Even teams that intend to filter often apply access rules at the wrong layer. They rely on the application to strip sensitive results after retrieval, or they trust the prompt to instruct the model not to reveal certain things. Both are fragile. Post-retrieval filtering means the sensitive chunk was already fetched, logged, and possibly cached before anyone decided to hide it. Prompt-level instructions are suggestions, not guarantees; a slightly reworded question routes around them.

The root cause is architectural. When content and its permissions live in different systems, the retriever has no authoritative way to know that a given chunk is confidential. The metadata that should carry that signal was either never attached during ingestion or drifted out of sync the moment the source document changed. Preventing leakage therefore starts long before the query: it starts with keeping the rules about content attached to the content itself, so that retrieval can never see a document without also seeing who is allowed to read it.

Classify and govern content where it is authored, not at query time

The most reliable place to decide whether content is confidential is where it is created and edited, because that is where a human already understands its sensitivity. If a document is modeled with an explicit audience, classification, or visibility field at authoring time, every downstream system inherits that signal for free. The alternative, inferring sensitivity at query time with a classifier or a regex, is a guess made under latency pressure with none of the context the author had.

This is where modeling your business, the first pillar of the Content Operating System, does real security work. In the Content Lake, confidential status is not a tag glued on after the fact; it is part of the document's schema, versioned alongside the content and queryable by the same GROQ that powers retrieval. An editor marking a document as internal in Sanity Studio is making a governance decision that the retrieval path can enforce directly, rather than hoping a separate ingestion job copied that decision correctly into a vector database.

Because the classification lives with the content, it also survives change. When a contract clause moves from draft to confidential, or a product spec is cleared for public release, the field updates in one place and the retrieval layer reflects it immediately. There is no window where the embedding index still believes yesterday's classification. Governing content at the source turns leakage prevention from a pipeline of best-effort filters into a property of the data model, which is the only version of it that holds up under audit.

Filter at retrieval, inside the query, not after the results come back

A control that runs after retrieval has already lost. By the time an application inspects results and decides to drop the confidential ones, those chunks have crossed a trust boundary: they were read out of storage, ranked, and handed to code that logs and caches. The safe design is to make confidential content unreachable by the query in the first place, so a disallowed chunk is never a candidate for the answer.

This is the practical advantage of retrieval that lives inside the content backend rather than in a bolt-on vector store. In Sanity Context, hybrid retrieval runs as a single GROQ query that blends semantic and keyword matching, `text::semanticSimilarity()` for meaning and `match()` for exact terms, combined with `score()` and `boost()` to rank results. Because it is a GROQ query, the same filter expressions that enforce a document's visibility field run in the same pass as the ranking. The permission predicate and the relevance ranking are not two systems that have to agree; they are one query.

Contrast that with a standalone vector database, where similarity search and access control are separate concerns. You either replicate every permission change into the vector store's metadata and filter on it, hoping the copy stays consistent, or you filter in application code after the search returns. The first is a synchronization problem that fails silently; the second is post-retrieval filtering with all its exposure. Folding the access predicate into the retrieval query removes the gap entirely: content the caller may not see is simply not in the result set, because the query that would have returned it never could.

Keep embeddings honest so freshly-restricted content stops matching

A subtle and dangerous form of leakage is temporal. A document is public, gets embedded, and is later reclassified as confidential, but the embedding lingers in the index representing the old, permissive state. The vector still matches queries and still points at content that is now restricted. In a pipeline where embeddings are generated by a separate job on a schedule, this drift is not an edge case; it is the normal state between sync runs.

The fix is to stop treating embeddings as a derived artifact that lives apart from the content. When embeddings are tied to the content itself, a change to a document, including a change to its classification, propagates to the retrieval representation within minutes, with no separate vector pipeline to babysit. There is no standing reconciliation job that can fall behind, and no window where the index disagrees with the source of truth about what a document is or who may see it.

This matters for leakage specifically because reclassification is common in regulated work. Legal holds get applied, embargoed announcements get set, personnel records get sealed. Each of those is a moment where the retrieval layer must catch up fast, and every minute of lag is a minute the old content is still answerable. Dataset embeddings that update with the content collapse that lag. Combined with a classification field in the schema and an access predicate in the query, they close the last of the three windows through which confidential content escapes: stale representations of content that used to be safe to surface.

Stage and review agent behavior before it reaches production

Leakage is not only about which documents are reachable; it is also about how the agent is instructed to behave. A system prompt that tells the agent to be maximally helpful, an over-broad tool scope, or a Knowledge Base that quietly ingested a folder it should not have, each of these can turn a well-governed content store into a leaky one. The controls on agent behavior deserve the same review discipline as a website deploy, because a bad instruction ships to every user at once.

Automating everything, the second pillar, does not mean automating blindly. In Sanity, agent instructions and Knowledge Bases are content, edited in the Studio and stageable through Content Releases the same way editors stage a site launch. That means a change to what an agent is allowed to retrieve, or a new source added to a Knowledge Base, can be previewed, reviewed, and approved before it goes live, rather than pushed straight to production as a config change nobody read. The people who understand content sensitivity are the same people governing the agent.

Production agents connect through the Sanity Context MCP endpoint, which means the retrieval they perform runs through the same permission-aware GROQ path described above, not a side channel with its own rules. Governance is not a separate compliance layer sitting outside the system; it is the editorial workflow your team already trusts, extended to cover what the agent knows and how it answers. Reviewing agent behavior before release turns the most common human-error leak, someone pointing an agent at the wrong content, into a caught mistake instead of an incident.

Prove it: audit, data residency, and the evidence auditors want

Preventing leakage is only half the obligation. The other half is demonstrating, after the fact, that a given piece of confidential content could not have been surfaced to a given user, and being able to show exactly what the agent retrieved and when. Enterprises in regulated sectors cannot rely on trust; they need an evidentiary trail and controls a third party will accept.

Sanity's compliance posture supports that requirement with SOC 2 Type II, GDPR alignment, regional hosting and data residency options, and a published sub-processor list, so teams can place content in a jurisdiction that matches their obligations and document who touches it. Roles and Permissions govern who can read, edit, and reclassify content in the first place, and Audit logs record the changes that matter when an investigator asks who reclassified a document and when. Because retrieval, classification, and permissions all live in the same system, the audit story is coherent rather than stitched together from a vector store's logs, a CMS's history, and an application's request traces.

This coherence is the payoff of grounding agents in a Content Operating System rather than a pile of loosely coupled services. When the access predicate, the classification field, the embedding, and the audit record all describe the same document in the same place, you can answer an auditor's question with a query instead of an archaeology project. Leakage prevention that you cannot prove is not much use in an enterprise; the controls and the evidence have to come from one system, and that is the case Sanity Context is built to make.

Where access-aware RAG retrieval actually lives

FeatureSanityPineconeContentfulpgvector / Neon
Confidentiality classificationModeled as a schema field on the document in the Content Lake, versioned with the content and queryable by GROQStored as vector metadata you populate and keep in sync yourself; no authoring contextContent-type fields hold classification, but retrieval runs in an external search or vector serviceA column you design; classification and its meaning live in your application, not the store
Access filter at retrievalPermission predicate runs in the same GROQ query as ranking, so disallowed content is never a candidateMetadata filters at query time work, but permissions must be replicated into the index to enforce themTypically post-retrieval filtering in app code after an external search returns resultsWHERE clauses can filter, but you build and maintain the access logic in application SQL yourself
Hybrid semantic + keywordNative: text::semanticSimilarity() and match() blended with score() and boost() in one queryNative dense plus sparse hybrid search; keyword handling depends on your embedding and index setupNo native hybrid; assembled from Contentful plus an external search or vector providerpgvector for similarity plus Postgres full-text search, combined in SQL you write and tune
Embedding freshness on reclassifyDataset embeddings tied to content propagate changes within minutes; no separate sync job to driftReclassification requires re-upserting vectors and metadata; freshness is your pipeline's responsibilityDepends on a re-index job to the external store; a window of stale state between runsYou run the re-embedding and update yourself; drift persists until the next batch
Governing agent instructionsInstructions and Knowledge Bases are content, staged and reviewed through Content Releases before going liveOut of scope; prompt and tool governance handled entirely in your application layerEditorial workflow exists for content, but agent instruction governance is not part of the platformNo content or agent governance layer; entirely up to your application
Audit and data residencySOC 2 Type II, GDPR, regional hosting, published sub-processors, Audit logs, and Roles and Permissions in one systemSOC 2 and regional options available; audit spans your app plus the index, not one content systemEnterprise compliance and roles for content; agent retrieval audit trail lives in the external stackInherits your cloud's compliance; audit and residency are yours to assemble and evidence