Permission-aware RAG: design a safer internal knowledge assistant.
An internal knowledge assistant should retrieve only information the requesting user may access. Apply permissions before model context is assembled, preserve source versions, and test revocation and cross-tenant isolation separately from answer quality.
Inside this article 6 sections +
The most dangerous answer from an internal assistant may be perfectly accurate. It can quote a confidential document, identify the right customer, and summarize the facts clearly—while showing them to someone who should never have had access. Answer quality and permission correctness are different properties, and a useful design measures both.
Consider an illustrative company with shared product documentation, team-specific planning notes, and restricted customer records. An employee asks why a feature was delayed. Several documents contain relevant words, but only some belong in that employee’s answer. The retrieval system must make that distinction before it hands context to a model.
The retrieval boundary comes before the prompt
Start each request with a verified user identity and the current organizational context. Determine which tenants, projects, or document groups that user may access. Apply those permissions while selecting candidate documents, then verify the selected records before assembling model context. A prompt instruction to ignore restricted material is too late if the material has already reached the model.
Where PostgreSQL stores documents or their metadata, row-level security can be one part of the enforcement design. It is not automatically active, and privileged roles or table ownership can affect whether policies apply. Test through the exact database role and connection path used by the assistant. A development query that behaves correctly under one account says little about a production service account with broader privileges.
Follow every copy of a document
A knowledge pipeline can create several representations of the same source: extracted text, chunks, embeddings, summaries, search indexes, caches, and logs. Revoking access only in the original document store leaves those copies as possible disclosure paths. Give each representation a source identifier and version so that a permission change or deletion can be traced through the system.
Choose a revocation policy explicitly. A highly sensitive source might require a fresh permission check on every retrieval. A less sensitive collection may tolerate a defined synchronization window. In either case, make the window visible to the people responsible for the data. “Eventually updated” is not a useful operating agreement when nobody knows how long “eventually” can last.
Cache design belongs in this discussion. A cached answer can contain information assembled under a different user’s permissions. Include the relevant authorization scope and source version in cache decisions, or avoid sharing those answers. When access changes, cached answers need an invalidation or revalidation path. Do not rely on the wording of the user’s question to distinguish safe cache entries.
Treat documents as evidence, not instructions
A retrieved document can contain text that tells the assistant to reveal secrets, contact another system, or ignore its task. That text is still document content. Keep it separated from application instructions and give the answer-producing component only the tools it needs. A read-only assistant does not need a general-purpose execution tool merely to summarize a policy.
Validate proposed actions outside the model if actions are later introduced. A document can describe how to approve a request without granting the assistant permission to approve it. This distinction becomes especially important when internal and external material enter the same search index. A helpful-looking support attachment should not acquire the authority of an administrator.
Build a test set around boundaries
Use synthetic users and documents to exercise the permission model. Create two tenants with similarly named projects, a document whose title is public but body is restricted, and a user removed from a project after an earlier successful query. Ask direct questions, indirect questions, and follow-up questions that rely on conversation history. The expected result is a permission-safe response, not a clever reconstruction of hidden content.
| Change or request | What the test must establish |
|---|---|
| User moves between teams | Old team context cannot survive through history or cache. |
| Two tenants use the same project name | Relevance cannot cross the tenant boundary. |
| A source is removed | Its derived text and cached answers follow the removal policy. |
| A document contains instructions to the assistant | Those instructions cannot expand tools or permissions. |
| Two authorized sources disagree | The answer exposes the disagreement and identifies both versions. |
Evaluate answer usefulness separately. Can a reader locate the supporting source? Does the answer distinguish a current policy from an old proposal? Does it admit when the accessible material is insufficient? A permission-safe system that cannot answer useful questions still needs work, but improving retrieval should never involve silently broadening access.
Run a permission-change drill from question to follow-up
A concrete drill makes the access model easier to assess. Create a synthetic employee, Mira, with access to a shared product collection and a restricted pricing project. Add one document to each collection and give them deliberately overlapping language. Ask a question whose complete answer needs both documents. Before access changes, verify that the assistant can identify the permitted evidence and associate it with the correct source versions.
Now remove Mira from the pricing project and repeat the question. Inspect more than the final answer. Check the retrieval results, the context prepared for the model, any cached result selected by the application, and the records available to the support interface. A safe-looking final answer can hide a failed boundary if restricted text entered the model context and was merely omitted from the response.
Next, continue the original conversation with “What did that pricing document say about the exception?” The application needs a policy for previously retrieved context when access changes. One approach is to reauthorize source references before using earlier turns as evidence and remove restricted retrieved excerpts from subsequent model input. Revocation cannot undo information already shown to someone, but it should prevent the assistant from continuing to retrieve or reuse it as if access still existed.
Repeat the drill while the search index is behind the source system. If the permitted synchronization window has not elapsed, the result should match the documented access policy; if immediate revocation is required, a final authoritative check must prevent stale index permissions from deciding access. Test what happens when that check is unavailable. An unavailable permission service should produce an explicit failure or a restricted fallback, not broaden retrieval.
Keep the drill small enough to rerun whenever connectors, caching, or conversation handling change. Record the identities, source revisions, permission changes, and observed boundaries. This gives the team a reproducible way to distinguish a retrieval-quality problem from a permission failure, and makes review discussions more concrete than asking whether the assistant “seems secure.”
Give the knowledge lifecycle an owner
Assign responsibility for source onboarding, access synchronization, stale documents, evaluation failures, and user reports. Track the age of each source collection and the time taken to process revocations. The assistant is an ongoing information product, not simply an index created once and left running.
For the surrounding application design, read integrating AI into existing SaaS. Our AI integration services can help connect retrieval, evaluation, and operational ownership to your existing systems.
Access control also needs a source-removal process. Explore that lifecycle in Delete a document across the whole RAG pipeline.