Black Friday50% off your first month on any monthly plan with EARLY50 See plans
All 29 lessons
  1. Foundations: what RAG is and a working pipeline

    1. 1. Getting started: what RAG is and when to use it
    2. 2. Types of RAG: a map from naive to agentic
    3. 3. Lab: build the smallest RAG pipeline end to end
    4. 4. How embeddings and vector search find meaning
    5. 5. Document types: what each one breaks, and how to prepare it
  2. Better retrieval: chunking and search

    1. 6. Chunking documents so answers survive
    2. 7. Chunking strategies compared: which to use when
    3. 8. Keyword search vs vector search, and fusing both
    4. 9. Retrieval algorithms compared: which to use when
    5. 10. Reranking the top results before the model reads them
    6. 11. Rewriting the question before you search
  3. Answers you can trust, measure and debug

    1. 12. Lab: grounded answers with citations and refusals
    2. 13. Measuring a RAG system with an evaluation set
    3. 14. Lab: evaluation methods and frameworks: Ragas and DeepEval
    4. 15. Troubleshooting a RAG system, symptom by symptom
  4. Production in a company

    1. 16. Access control: only retrieve what the user may see
    2. 17. Defending against prompt injection in retrieved text
    3. 18. Running RAG in production: freshness, cost and monitoring
    4. 19. Real-world RAG: what worked, what failed, and why
  5. Agentic RAG

    1. 20. Lab: from a fixed pipeline to an agent with a search tool
    2. 21. Self-correcting retrieval: grade, retry, fall back
    3. 22. GraphRAG and routing across many sources
    4. 23. Lab: numbers, tables and financial documents
  6. Frameworks: LangChain, LangGraph and LangSmith

    1. 24. The RAG toolbox: what each library does and why you import it
    2. 25. The framework landscape: LangChain, LangGraph, LlamaIndex, Haystack
    3. 26. Lab: Ask Brightline in LangChain
    4. 27. Lab: agentic RAG as a LangGraph graph
    5. 28. Lab: tracing, evaluating and monitoring with LangSmith
    6. 29. Wrap-up: your production agentic RAG checklist
See the leaderboard

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:

  1. 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.
  2. 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.

[15]

Where the permission check sitsSource system with ACLsIndex: chunk + allowed groupsSigned-in employeeIdentity provider: user's groupsSearch with group filterPrompt: only permitted chunksModelACLs copied onto every chunkwhen indexedfilter runs inside the search,before rankingnever sees what the user can't

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.

python
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 access
intern = {"all-staff"} # from the verified sign-in token
print([c["id"] for c in CHUNKS if allowed(c, intern)])
Expected output: ['hr-pto']. In production the filter runs inside the search service, before ranking.

Filter early, not late

Where you filter matters:

  • Inside the search (pre-filtering). This is the default. The top results are all permitted, so k stays 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.

[15]

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.

[11]

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

  1. Authorization happens in code before retrieval, never in the prompt.
  2. Copy ACLs onto every chunk and filter by the caller's verified groups.
  3. Filter inside the search so k stays full of permitted chunks.
  4. 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.

  1. [11]OWASP Top 10 for LLM Applications 2025
  2. [15]Microsoft Learn: Security filters for trimming results