recallA retrieval
field guide

Permission-aware Retrieval

Build this skill

Enforce user permissions inside retrieval so the assistant never reveals what a user cannot open.

The assistant must not know more than the user

A knowledge base often holds documents meant for different people: student rules, staff HR policies, exam papers before the exam, disciplinary committee minutes, salary sheets. Each source system already controls who can open which file. A RAG assistant that indexes everything into one store and searches it for every user quietly removes those controls. A student's innocent question about leave could retrieve the staff leave policy; a cleverly worded question could pull a passage from confidential minutes into an answer.

Permission-aware retrieval makes sure that, for every question, the system only retrieves content the asking user is allowed to see. The rule is simple: the assistant must never reveal what the user could not have opened themselves.

Where to enforce permissions

There are three places permissions could be applied, and only one is safe on its own.

Approach How it works Problem
Ask the model to refuse Tell the model "don't reveal staff documents" The text is already in the prompt; the model can be tricked or simply slip
Filter after retrieval Retrieve top K from everything, then drop forbidden results Can leave too few results; easy to forget in one code path
Filter during retrieval Only search documents the user may see Correct by design, when metadata is right

Permissions must be enforced before content reaches the model, as part of the search itself: an access filter applied to every query by the system, based on the logged-in user's identity, never on what the question says. Prompts that ask the model to keep secrets are not a security control.

Logged-inuserroles: student,CSEBuild filterfrom identity,not questionFilteredsearchonly allowedchunksPromptallowed contentonlyAnswersafe by design

The user's identity decides the filter, and the filter is applied inside the search, before anything reaches the model.

Role-based access control

The most common model is role-based access control (RBAC). Users have roles (student, faculty, hostel warden, exam cell, admin), and every document records which roles may see it, as metadata copied from the source system during ingestion. At query time, the filter keeps only chunks whose allowed roles overlap the user's roles.

Some systems need finer control: document-level access lists naming specific users or groups (copied from SharePoint or Google Drive permissions), or attribute-based rules such as "students may see only their own department's internal notices". All of these become metadata filters in the end.

See what happens with and without a permission filter.

Getting permissions right in practice

Copy permissions from the source

Connectors should read each document's access list and store it on every chunk. Never invent permissions by hand inside the RAG system.

Keep them in sync

When someone loses access in the source system, the index must update too. A nightly sync that refreshes access metadata, plus immediate updates for urgent changes, closes the gap.

Fail closed

A chunk with missing or unreadable permissions should be treated as visible to nobody, not to everyone.

Check every path

Caches, conversation history, logs and evaluation tools can all leak content. A response cached for a staff member must never be served to a student.

Multi-tenancy

When one system serves several separate organisations (for example several colleges on one platform), each organisation is a tenant, and data must never cross between tenants. Common designs give each tenant its own collection or index, or a mandatory tenant filter on every query, enforced in one place in the code.

The program below enforces a role filter inside search and fails closed for chunks without permissions.

python · runs in your browser

Expected output:

text
student: ['Students may take up to 10 days of medical leave.', "A doctor's certificate is needed within 7 days."]
HR:      ['Faculty may take 20 days of medical leave per year.', 'Students may take up to 10 days of medical leave.', 'Minutes: leave misuse case of a staff member.']

The filter is inside search, before ranking. A chunk is visible only if it has an allowed list and that list shares at least one role with the user (set(c["allowed"]) & set(user_roles)). The is not None test is the "fail closed" part: a chunk with no access information is hidden from everyone, not shown to everyone.

The student sees only student content; the chunk with no access information is hidden from everyone until someone fixes its metadata.

Follow your curiosity.

↑ ↓ to explore · Enter to open · Escape to close