Security
Permissions belong in the retrieval layer, not the prompt
- Written by
- The PrizenLabs team
- Published
- Reading time
- 5 min
On this page
The fastest way to build an internal AI assistant is to index every document the company has and let the model answer from them. It demos beautifully. Then someone in sales asks about pay bands, or a contractor asks about an acquisition that has not been announced, and the assistant answers helpfully, with citations.
That is not a model failure. The model did what it was asked: answer from the documents it was given. The failure is that it was given documents the person asking was never allowed to read.
Why the prompt cannot fix it
The tempting fix is an instruction: "Do not reveal information the user is not authorised to see." It fails for three reasons.
The model does not know who is authorised. Permissions live in your identity provider, your document stores and your file shares, in groups and inheritance rules the model has never seen. An instruction cannot enforce a rule the model has no way to evaluate.
Instructions can be overridden. A determined user can talk a model out of its instructions, and so can text inside a retrieved document. OWASP lists sensitive information disclosure among the top risks for LLM applications; once restricted text is in the context window, every defence after that point is a matter of probability.
Leaks are not only in answers. A summary that never quotes the restricted document can still reveal that it exists, what it is about or which deal it concerns. Even a citation leaks a title.
The only reliable rule is the simplest: the model must never see text the user could not open themselves.
Where the check belongs
Retrieval is a pipeline: ingest, chunk, embed, index, search, rerank, generate. Permissions have to travel with the data through every stage and be applied at search time, before anything reaches the model.
At ingestion: copy the permissions with the content
When a document is ingested, we record who may read it alongside its chunks: the users and groups on the source system's access list, including permissions inherited from folders and sites. Every chunk carries the access list of the document it came from. A chunk without one is not indexed.
Some documents need finer rules than one access list: a board pack with one restricted section, or a ticket with internal notes beside the customer's messages. Where the source system expresses that boundary, we split the document along it and give each part its own list. Where it does not, the whole document takes the strictest list that applies to any part of it.
At query time: filter before ranking
When a person asks a question, we resolve who they are and which groups they belong to from your identity provider, never from anything the user types. The search narrows candidates to chunks they may read before ranking and reranking. Filtering after ranking is a common mistake: it is slower, it can leave too few results, and a bug in the filter fails open.
Most vector databases support metadata filters for exactly this, and so does Postgres with pgvector, where access rules sit beside the embeddings and can be enforced with ordinary row-level security.
At generation: cite only what was retrieved
The model answers only from the filtered passages, and every citation is checked against them after generation. If an answer cites something outside the permitted set, it is dropped. We cover citation checks in more depth in RAG still hallucinates.
Keeping permissions fresh
Permissions change all the time: people join, move teams and leave; documents are shared and unshared. An index built once is out of date within days.
- Sync permission changes, not just content changes. A document whose text is the same but whose sharing has changed must be stamped again in the index promptly.
- Resolve groups at query time. Store group identifiers on chunks and resolve the person's current memberships when they ask, so removing someone from a group takes effect at once.
- Key every cache to permissions. Cached answers and cached retrieval results must be keyed to what the person may read, or one person's answer is served to another.
- Delete properly. When a source document is deleted, its chunks, embeddings and any facts extracted from it go with it.
Test it like a security control
Because it is one. Next to the evaluation set that measures answer quality, we keep a permissions suite: pairs of people and questions where the right answer is that they have no access to anything on that subject. It runs on every change to ingestion, search and prompts, and it reports the number of restricted chunks retrieved, which should be zero.
We also test the awkward paths: a person removed from a group five minutes ago, a document moved into a restricted folder, a question phrased to fish for the existence of a restricted project.
When the data cannot leave at all
Access control decides who inside your organisation may read what. Some data also may not leave the organisation, whoever is asking: privileged legal material, patient records, defence work. Then the model itself has to run on infrastructure you control. Holmes, the legal AI we built, keeps documents on the user's machine and can run with a local model for offline use. For an organisation, the equivalent is a private LLM deployment inside your network.
What we build
Permissions-aware search is part of the retrieval stack we bring to every RAG engagement: access lists captured at ingestion, filters applied at query time, citations checked after generation, and a permissions suite in CI. It matters most where the stakes are highest, in legal and professional services and financial services.
If you are planning an assistant over your company's documents, ask one question before any other: what happens when someone asks about something they are not allowed to see? If the answer involves the prompt, let's talk.