Why filtering the answer is not enough
RAG is usually described as finding passages by meaning and passing the retrieved context to a model. For internal documents, the flow needs one more mandatory question: is this particular employee allowed to read each passage that was found?
If the system retrieves a restricted document, sends it in the prompt, and then asks the model “not to disclose anything it should not,” the control has already come too late. The model received the text, so it can influence an answer, citation, summary, tool call, log, or cache. OWASP guidance for LLM applications recommends checking access before retrieval rather than relying only on a filter over the finished answer.
This is a concrete issue for a small business: one knowledge base may contain price lists, procedures, contracts, personal data, and management documents. Making answers smart is not the difficult part; the harder part is ensuring that a manager can see a customer procedure but not an HR file, while a contractor can access only their project material.
A working pattern: permissions travel with the document
A basic architecture has four links:
1. The source of truth—a file portal, CRM, or procedure library—defines the ACL: users, groups, owner, and sensitivity.
2. During indexing, every document and each of its passages receives stable `document_id` and `chunk_id` values, a version, a source reference, and verified access attributes. When a document is split, its permissions must be inherited by every chunk; losing the ACL at this step can make a protected page retrievable as an unrestricted passage.
3. Before a query, the application authenticates the employee, obtains current groups from a trusted system, and builds a filter from them. The filter is applied in the same index request that performs full-text or vector search.
4. Only permitted passages enter the prompt. The answer links to sources already checked by the application, not to links generated arbitrarily by the model.
The model handles wording and synthesis; it does not decide who should have access. That decision is made before the content leaves the index.
Two ways to express permissions
A small independent implementation often uses a filter over principal IDs. The index stores a filterable field with group or user identifiers, and the application passes a trusted list for the current request. Microsoft describes this pattern for Azure AI Search: a field with group/user IDs and a query filter exclude documents not associated with the principal. The approach is not tied to a particular language model, but the application must authenticate the person itself and apply the correct filter to every query.
If a corporate repository exposes ACLs and the indexer can synchronize them correctly, prefer the source's native access-control mechanisms. Azure AI Search documentation describes permission indexing and query-time checks. Details and availability depend on the source, API, and configuration. Do not assume one generic design works identically for SharePoint, object storage, a network share, and a custom CRM.
For an SMB, the key decision is not which search engine is fashionable. It is a clear contract: which system issues permissions, how groups are refreshed, where the user is checked, and who is responsible for preventing a filter bypass.
Which fields to keep
A minimum set for documents and their passages includes:
- `document_id` and `chunk_id`, to connect a passage to its source object;
- `source_uri` or a stable internal identifier;
- `allowed_principals` or another verified set of rules;
- source version or synchronization time;
- document status: active, deleted, or archived;
- where needed, data category, department, and tenant.
Do not treat group names found in document text as permissions. Access attributes must come from an authoritative source ACL or a controlled administrative process. Otherwise, a line such as “access granted to everyone” inside an uploaded file could be mistaken for policy.
Separate indexes by branch or customer can sometimes be simpler than complex logic. This increases operating costs but can reduce the risk of a filter mistake in a sensitive environment. The choice depends on customer independence and the potential harm of a data crossover.
Synchronization matters as much as the filter
ACLs change: an employee leaves, a group changes membership, a contract ends, a folder moves, or access is revoked. The index may lag behind the source. Define the acceptable staleness window and update sequence in advance.
- Synchronize permissions with content instead of relying only on a nightly full reindex.
- When an item is deleted or access is revoked, close its derived chunks, cached answers, and links.
- Account for propagation delay in the identity system's group membership.
- Invalidate caches when an answer depends on the user and their permissions.
- Do not treat a link to the original as sufficient protection: the passage may already have appeared in the answer.
If immediate ACL updates are impossible, a safer option is to temporarily exclude an item until its new permissions are confirmed. This reduces coverage but avoids turning index delay into disclosure.
Common failure points
**The filter runs after search.** Top-K passages are first selected for every user and some are removed later. A restricted passage may already have entered a reranker, prompt, telemetry, or intermediate cache. Apply permissions in the storage query before text reaches generation.
**Groups come from the client.** A `user_id`, group list, or filter in a browser request does not prove identity. The server must validate the session and obtain the principal from a trusted identity provider.
**The filter does not cover every route.** Search, preview, export, an agent tool call, a retry, fallback index, and admin console are separate paths. One unfiltered path can bypass the whole design.
**The cache is shared.** A cache keyed only by question is unsafe if it ignores the user, permissions, and index version. An answer obtained lawfully by one employee may be returned unlawfully to another.
**ACLs are lost during chunking.** The source document has permissions, but derived records do not—or receive a default “everyone” grant. Check the final index records, not just the source table.
**The system prompt is treated as enforcement.** “Do not show salaries” is not an authorization mechanism. Access control must still work when the model errs, ignores instructions, or receives a malicious document.
How to test before a pilot
Do not start by loading the full archive. Choose one library with clear permissions and 10–20 test documents at two or three levels: shared, department-only, and personal. Create test profiles and a “role × document” matrix.
For each document, test two scenarios:
- an authorized employee finds the material and receives the correct link;
- an unauthorized employee receives none of its passages in search results, model context, or citations.
Add negative queries: the exact title of a restricted document, a question with a clue from its contents, a synonym, a retry after access revocation, and the same question from two different roles. In a test build, logging chunk IDs, principal, and the applied filter is useful, but do not store full restricted text in shared analytics.
The release gate is not “the answer sounds convincing.” It is “restricted documents never entered model input.” Any violation blocks corpus expansion until fixed and the matrix passes again.
Economics and limits
ACL fields, synchronization, and testing cost more than a demo over open documents. But when permissions differ, they belong in the baseline RAG estimate. A fix after a leak costs more: teams must trace affected answers, logs, and caches, notify responsible people, and rebuild trust.
Permission-aware RAG does not replace access management in source systems, activity audits, backups, data classification, or model endpoint protection. Nor does it automatically prevent several individually permitted facts from being combined into a new sensitive conclusion. For legally significant data, separately assess applicable requirements, processing location, and log retention.
A practical two-week start
1. Choose one source with working ACLs and a business-side data owner.
2. Record the identity and group source, test matrix, and maximum synchronization delay.
3. Index documents with verified permissions and inherit them for every chunk.
4. Put the filter in the single server-side search path; do not let clients set ACL values.
5. Run positive and negative tests, including access revocation, caches, and citations.
6. Add another folder only after there are zero unauthorized hits.
For a business leader, the conclusion is simple: access-controlled RAG is not a prompt setting; it is the chain “identity → source ACL → filter before retrieval → chunk and cache checks.” A pilot can be limited to one repository and a small user group, providing early evidence of safety before the full corporate archive is indexed.
