Senior

How do you enforce access control in a RAG system?

How to answer it in an AI engineer interview: what is being tested, a step-by-step framework, a sample answer and the mistakes to avoid.

$19.99 on Gumroad, instant download40% off with code EARLYBF until Nov 3, 11:59 PM PTEARLYBF: 40% off until Nov 3

Smaller start: Score your answers against 50 rubrics, $9. 50 AI engineer questions, one rubric each, PDF on Gumroad.

Practiced one out loud? Paste your answer into the free self-check and get a score in 30 seconds

What the interviewer is testing

Whether you treat permissions as a retrieval-layer control rather than a prompt instruction, and whether you think about sync, caching and testing.

Answer framework

  1. Attach permission metadata to every chunk at ingestion: tenant, groups, document ACL, sensitivity.
  2. Filter inside the retrieval query, using the caller's identity, before anything reaches the model.
  3. Never rely on the prompt to hide documents the user should not see.
  4. Keep ACLs in sync with source systems, including revocations, and scope caches by permission.
  5. Test with users who should and should not see each document, and log what was retrieved.

Sample answer

The rule I follow is that the model should only ever see text the user is allowed to read. So access control belongs in retrieval, not in the prompt. At ingestion I copy the source system's permissions onto each chunk: tenant ID, allowed users or groups, and a sensitivity label.

At query time the application resolves the user's identity and groups and passes them as a filter inside the vector or keyword search, so forbidden chunks are never candidates. Post-filtering after retrieval is weaker, because it can return too few results, and asking the model not to reveal certain documents is not a control at all, since prompt injection or a clever question can extract them.

The hard part is keeping permissions current. When someone loses access to a folder in the source system, the index has to reflect that quickly, so I sync ACL changes separately from content changes. Any cache of answers or retrieved chunks must be keyed by user or permission set. Finally I test with pairs of users, one who should see a document and one who should not, and I log retrieved chunk IDs for audits.

Likely follow-ups

Pre-filtering vs post-filtering? Pre-filtering applies permissions in the search itself so top-k is all allowed content; post-filtering drops results afterwards and can leave too few or leak through bugs.

Common mistakes

The PlaybookWant the full method?

The 0 to 1 AI Engineer Interview Playbook covers the answer frameworks, system-design walkthroughs and an 8-week plan.

Get the playbook 40% off with code EARLYBF until Nov 3, 11:59 PM PTEARLYBF: 40% off until Nov 3

Smaller start: Score your answers against 50 rubrics, $9. 50 AI engineer questions, one rubric each, PDF on Gumroad.

Interviewing for PM or TPM? See the full PM package, $59 on Gumroad: a resume system, a PM, TPM and PGM interview handbook, a 1:1 cheat sheet and a PM playbook. PM and TPM content, not AI engineer prep.

Related questions

Based on question #38 in the full question bank.