All 29 lessons
Foundations: what RAG is and a working pipeline
Better retrieval: chunking and search
Answers you can trust, measure and debug
Production in a company
Agentic RAG
Frameworks: LangChain, LangGraph and LangSmith
- 24. The RAG toolbox: what each library does and why you import it
- 25. The framework landscape: LangChain, LangGraph, LlamaIndex, Haystack
- 26. Lab: Ask Brightline in LangChain
- 27. Lab: agentic RAG as a LangGraph graph
- 28. Lab: tracing, evaluating and monitoring with LangSmith
- 29. Wrap-up: your production agentic RAG checklist
15 min
Access control: only retrieve what the user may see
Enforce document permissions at retrieval time so the assistant never leaks restricted content.
By the end of this lesson you can
- Explain why prompt instructions are not access control
- Design security trimming: permissions stored per chunk, filtered at query time
- Spot the places a RAG system can leak restricted content
From earlier lessons · 1 of 2
Your reranker raised recall@1 but lowered recall@3. What's the next step?
Pick one answer.
From earlier lessons · 2 of 2
What does faithfulness measure?
Pick one answer.
An intern asks Ask Brightline: "What's the salary band for senior analysts?" The HR compensation file is in the index. Retrieval finds it, the answer cites it, and the faithfulness judge scores it perfect. It's also a serious data leak.
The idea that was missing
Every lesson so far asked one question: is this chunk relevant? A company assistant must also ask: is this person allowed to see it? Brightline's index mixes documents for all staff, for managers, for HR and for security. Relevance alone will happily hand the HR file to anyone who asks the right question.
The first instinct is a rule in the system prompt: "Never reveal salary information." That isn't access control. The restricted text is already in the prompt. A rephrased question, a summary request or an injected instruction can get it out. Lesson 17 shows how. Authorization must happen in code, before the text reaches the model.
Security trimming, in plain words
Security trimming means each user's search only ever sees the chunks they're allowed to read. It has two halves:
- At indexing time, copy each document's access control list (ACL) into metadata on every chunk. That's the list of groups allowed to read it.
- At query time, look up the caller's groups from their verified sign-in, never from what the request says. Pass them as a filter inside the search itself.
Microsoft's Azure AI Search guide uses this pattern. It stores group ids in a filterable field and applies a filter on every query, so the search returns only documents the caller can read.
Think of a library with a locked archive. The librarian checks your badge before fetching books, not after reading them to you. A note saying "please don't repeat what's on page 4" is no protection once the page has been read aloud.
CHUNKS = [{"id": "hr-pto", "groups": {"all-staff"}},{"id": "hr-salary-bands", "groups": {"hr", "people-managers"}},{"id": "sec-incident-2026", "groups": {"security"}},]def allowed(chunk, user_groups):return bool(chunk["groups"] & user_groups) # any shared group grants accessintern = {"all-staff"} # from the verified sign-in tokenprint([c["id"] for c in CHUNKS if allowed(c, intern)])
Filter early, not late
Where you filter matters:
- Inside the search (pre-filtering). This is the default. The top results are all permitted, so
kstays full. - After search, before the prompt (post-filtering). This is safe, but if 8 of your top 10 are restricted, the model gets 2 chunks and weaker answers.
- After generation, or in the prompt. Never. By then the restricted text has been processed, and may be logged or cached.
Mark the permission field as hidden from results, too. Microsoft notes that hiding a field isn't field-level security, though. The filter on every query is what enforces access.
The other ways content leaks
Filtering search closes the main door. Check these side doors too:
- Stale permissions. Someone leaves HR, but the index still lists them. Re-sync ACLs whenever the source changes, and check whether your connector captures permissions only at first indexing.
- Shared caches. An answer cached for an HR manager and served to the next person with the same question leaks the whole answer. Include the user's permission set in the cache key.
- Embeddings and logs. Vectors can leak meaning, and request logs hold full prompts. Restrict both like the source documents.
- Tenants. If you serve several clients, give each its own index, or make the tenant filter impossible to omit.
OWASP's 2025 Top 10 for LLM applications lists two of these risks. LLM02 is Sensitive Information Disclosure. LLM08 is Vector and Embedding Weaknesses, which includes access leaks through the retrieval layer.
Match
Match each leak to its fix
Pick an item on the left, then its match on the right.
Predict, then reveal
Predict it: Ask Brightline adds a "summarise this week's new documents" feature that runs as a scheduled job. Whose permissions should it use?
Worth keeping
- Authorization happens in code before retrieval, never in the prompt.
- Copy ACLs onto every chunk and filter by the caller's verified groups.
- Filter inside the search so k stays full of permitted chunks.
- Check the side doors: stale ACLs, shared caches, logs and tenants.
Trimming controls what Ask Brightline reads. But what if a document everyone is allowed to read contains instructions aimed at the model? Next lesson: when your own wiki attacks your assistant.
Leaderboard
Loading…
50 XP for each lesson you finish, 10 for each right answer. Names show only for learners who turn on Show me on leaderboards.
Sources for this lesson (2)
Each fact in the lesson is marked with the number of the page it comes from.