A tiny two user test that makes permission bugs in a RAG application much harder to miss.
Your assistant answers the question beautifully. It finds the relevant document, summarizes the right paragraph, and even adds a citation.
Then someone points out that the person asking the question was never supposed to read that document.
Honestly, that is an uncomfortable demo. Nothing needed to hallucinate for the system to get this wrong. The answer can be completely accurate and still be an answer you should not have delivered.
Enterprise AI is showing up in Medium’s trending conversation again, and the temptation is to start with better models, richer context and smarter search. I want to spend a little time on a less glamorous question that belongs in the same design discussion.
Whose context are we handing to the model?
Retrieval augmented generation, usually shortened to RAG, gives a model relevant material from a document collection before it answers. That retrieval step is also where a perfectly ordinary permission mistake can become an unusually fluent disclosure.
If you are building a document assistant, preparing an AI engineering project, or practicing system design, try the small exercise below. You can begin with a few synthetic documents and ordinary filtering code, before spending anything on embeddings.
Give two people the same question
Imagine an internal assistant for a fictional company. Maya works in support, Leo works in finance, and both ask how refunds are handled.
For this exercise, there are three documents. Both people can read the public refund policy. Maya can also read customer case notes, while Leo can read an internal margin plan. Neither can read the other team’s private document.
Those permissions are deliberately simple. A real organization might decide access by customer assignment, project membership or individual grants rather than department alone.
Now run the same query as both users. Their relevant document sets may overlap, but their allowed document sets are different.
Here is the first rule for our exercise. Every private passage supplied as context for a user’s answer must come from a source that user is currently authorized to read, within the correct tenant.
Relevance does not override that rule. Neither does the fact that the service account used to build the index could read everything.
If the first version searches all documents and asks the model to hide confidential material afterward, the sensitive passage has already reached the model context. Removing its citation at the end does not undo that exposure.
Put the permission decision before the answer
Start the request with a verified user identity. Resolve the tenant and applicable permissions through trusted application code and your authorization system, rather than accepting a role typed into the question.
Then restrict retrieval to the permitted scope. Preserve the source’s access information when creating chunks, so splitting one document into twenty passages does not accidentally make those passages public.
For our small example, the filter needs both the tenant boundary and the document’s access rule. Being a support employee at one company does not authorize access to support documents at another company. Role names are not globally unique security boundaries.
I prefer writing the expected source IDs before generating any prose. Maya’s context may contain the public policy and the permitted case notes; Leo’s may contain the policy and the margin plan. The model cannot repair a source selection that was wrong before it started answering.
To turn this into interview practice, open this production RAG design question and focus on its authorization and caching requirements first. Sketch the two-user example, identify where permissions are enforced, and explain what changes when one user loses access. That is a much more useful rehearsal than memorizing another diagram full of arrows.
Microsoft’s document-level access guidance describes both security filters and identity-based approaches for excluding unauthorized search results. Its separate security-filter explanation makes an important distinction. Comparing identity strings in a filter does not authenticate the caller by itself.
Your application still has to establish who is asking and supply the correct scope. A field containing a user ID is not a magic security feature just because it sits beside an embedding.
Follow the private text beyond the search result
Getting retrieval right is necessary, but your application probably has more places where text can travel.
A reranker might receive candidate passages before the final selection. Debug logs might record the full prompt. A tracing tool might retain retrieved snippets, and conversation history might carry an earlier answer into the next request.
Draw that route once, even if the drawing is gloriously untidy. Mark which components are trusted to process which data, and where user-visible or external systems receive it.
In this example, filter before passing passages to downstream model services that should not see unauthorized material. Keep logs and traces access-controlled and avoid recording raw private passages when identifiers and decision metadata are enough for debugging.
Also test the citation endpoint. A carefully scoped answer is not much comfort if changing the document ID in a preview URL opens any file in the index.
Permission checks belong on the server paths that return content, including previews and downloads. Hiding a button in the interface only changes what the interface shows.
Ask again after access is revoked
Now give Maya access to a private document, ask a question, and let the application cache the answer. Remove her access and repeat the request.
This is where an otherwise tidy demo can become awkward again. A cache keyed only by the question may return the old answer without running retrieval at all.
Adding the user ID prevents some cross-user reuse, but it does not solve access changes for that same user. The answer was permitted yesterday and may be forbidden today.
For private answers, define how cache entries depend on tenant, authorization scope, source versions and permission changes. One conservative starting point is to bypass shared answer caching, then revalidate access to the sources before reusing any private cached response. More sophisticated sharing requires a clear definition of equivalent access.
Expiration alone leaves a window between a permission change and the expiry. Decide what revocation guarantee the product needs and how the implementation will meet it. If the permission index updates asynchronously, that delay is part of the design, not a footnote to discover later.
When fresh authorization cannot be established, our exercise withholds the private material. It does not drop the filter to make the answer more helpful.
Previously disclosed information cannot be made unknown to its recipient. The achievable goal is to prevent new unauthorized retrieval or redisclosure, including reuse through cached answers and conversation context, according to the product’s policy.
That means the follow-up message needs attention too. Asking the assistant to expand its previous answer should not quietly reintroduce passages the current user is no longer allowed to receive.
Test the negative cases before polishing the demo
A useful test set needs cases where the system must withhold something, not only cases where it produces a great answer.
Use synthetic documents with distinctive harmless markers, then inspect the retrieved source IDs and assembled model context as well as the final output. A polite refusal at the end is not proof that the private passage stayed out of the pipeline.
- Ask the same question as Maya and Leo, and compare each result with the permission table.
- Repeat the query under another tenant with similarly named users and documents. Private context must stay within the correct tenant.
- Revoke access after a successful answer, then test the next query, cached response, follow-up message and citation preview.
- Remove permission metadata or make authorization unavailable. Confirm that the private document is withheld rather than treated as public.
- Add a document sentence that asks the assistant to change the user’s role. Verify that document text cannot change the server-side authorization decision.
That last case connects permissions to prompt injection without confusing the two. A retrieved document is content to examine, not an authority that can grant access or change the caller’s identity.
Keep two scorecards.
One asks whether the answer is useful and grounded and the other asks whether the request obeyed the intended access policy throughout the paths you tested.
Passing a handful of examples does not prove a production system is secure. It does give you concrete evidence, exposes missing controls, and makes the next review more productive than pointing at an impressive answer and hoping nobody asks about permissions.
For your next project session, start with the little permission table. Make the same question produce the correct allowed context for two different people, then change one permission and try again.
A better model might improve the answer. You still need a system that knows who is allowed to receive it.
~ Emily




