Retrieval and RAGAccess, completeness and answerabilityPrincipal
How do you enforce authorization when expanding an allowed search chunk into parent context?
By Amit Kumar3 min readWorked answer includedReviewed 28 Sept 2026
The question
Interview question
A permitted child paragraph ranks highly, but the RAG layer fetches its larger parent with a service credential. The parent contains another team’s restricted section and is cached by document ID. Design authorization over assembled context, handle mixed permissions and revocation, and test caches and citations before any private text reaches the model.
Draft your approach first
Take a few minutes before you read the answer. Name the constraint that matters most, the failure you are designing for and how you would know it worked.
Reveal the worked answerWorked answer
Suppose a search index stores small child chunks for ranking. It returns a paragraph the user may read. The RAG layer then replaces that paragraph with its larger parent document to give the model context. Somewhere in that parent is a section restricted to another team. The search filter did its job for the child. The expansion changed the object being disclosed.
Authorization has to hold for every piece of text that actually enters the prompt, not just the hit that selected it. A parent ID is a retrieval pointer, not evidence that all its descendants share one access rule. If permissions vary within a file, indexing the whole file as one authorized parent is the wrong security unit. Split content at permission boundaries, or expand only into spans independently authorized for this user. If the complete parent has a single ACL, recheck that ACL on the parent fetch and keep its permission version tied to the fetched content. Azure AI Search's security filtering guidance is explicit that a query must apply its identity filter to the documents it returns.
One design stores independently versioned spans with their own permission boundaries and an expansion map. The map proposes related context. It does not grant access to it. The assembler resolves each proposed span against the caller’s trusted identity, obtains the matching content revision, and adds only permitted spans to the prompt. If the task genuinely requires an unavailable exception, state that the evidence is incomplete rather than inventing a safe substitute.
The tricky implementation detail is the join. A child might carry allowed_groups=["all-staff"] while its parent is fetched by ID from an object store with a service credential. The object store cannot tell which end user is asking unless the application passes their identity or checks the returned content itself. A cached parent keyed only by document ID can widen the leak further. Search-time ACL filtering does not automatically protect that later object-store read.
A cached parent cannot be reused merely because its content revision matches. If cached bytes contain mixed permissions, selection must still enforce current access before output. Depending on the system, cache raw protected content in a restricted service and reauthorize selected spans, or cache already-authorized assemblies with the relevant identity and permission-version contract. Neither option makes a stale decision automatically current.
Tie content and permission checks to a coherent read where the source supports one. If an ACL changes between search and parent fetch, the later assembly gate must apply the defined freshness/revocation policy rather than trusting the old hit. Then inspect the exact serialized model context in a synthetic fixture, including headings, footnotes and citation snippets. A system that withholds the restricted paragraph but exposes its private title still fails the intended disclosure boundary.
I would test with two children under one parent that have different permissions. Log the IDs and permission decisions for both the matched child and every expanded span, then assert that the final model context and citations contain only allowed text. Include permission changes and cached expansion in the test. Do not expose a restricted title or snippet in a citation either.
If the interviewer suggests filtering the final answer instead, that is too late. The model has already consumed the private material, and a text filter cannot reliably undo that exposure. Make the authorization boundary the assembled context, including any parent expansion and tool fetch, before generation starts.
Related questions
Keep practising retrieval and rag
Follow another question in this area, or search the complete library.
Get my essays on AI engineering and distributed systems by email. Subscribe to ArchCrux