
Dan Patiño
AI Strategy & Innovation at Coderhouse
Artificial Intelligence
Permission-aware RAG is a retrieval-augmented generation system that only retrieves and shows a user the documents that user is already allowed to see. When someone asks an internal AI assistant a question, the system checks who is asking, filters the knowledge base by that person's access rights, and only then passes the matching chunks to the language model. If a sales rep cannot open the board deck in Google Drive, the assistant should not be able to quote it to them either.
This sounds obvious, but it is one of the most common gaps in enterprise AI projects. A prototype that indexes every file into a single vector store works beautifully in a demo, and then becomes a data leak the day it is rolled out to the whole company. For AI engineers who deploy systems inside client organizations, document-level access control is not an extra feature: it is the condition for going to production.
Why standard RAG leaks data
A basic RAG pipeline splits documents into chunks, turns them into embeddings, stores them in a vector database and retrieves the most similar chunks for each question. Nothing in that flow knows who the user is. Similarity search returns whatever is closest to the query, whether it comes from a public FAQ, an HR investigation or a pricing spreadsheet for a confidential deal.
The OWASP Top 10 for LLM Applications lists vector and embedding weaknesses, including unauthorized access and cross-context information leaks, as a distinct risk category. The problem is not the model "deciding" to leak; it is that the retrieval layer handed it information the user should never have reached.
Flattened permissions: files from many sources with different access rules end up in one index with no access metadata.
Stale permissions: someone loses access to a folder, but their old chunks stay retrievable.
Multi-tenant mixing: data from several customers lives in the same index and one tenant's query surfaces another tenant's content.
Prompt-only rules: the system prompt says "do not reveal confidential data", which is not an access control mechanism.
How permission-aware RAG works
The core idea is simple: carry the source system's permissions into the index and enforce them at query time, before generation. In practice it has four parts.
1. Capture access metadata at ingestion
When the pipeline pulls a document from SharePoint, Google Drive, Confluence, a CRM or a ticketing tool, it also reads that document's access control list: which users, groups or roles can view it. That information is stored as metadata on every chunk created from the document, for example allowed_groups: ["finance", "exec"] or a tenant ID.
2. Resolve the user's identity
At query time the application needs to know exactly who is asking. In enterprise settings this usually comes from single sign-on, with the user's ID and group memberships taken from the identity provider. If the assistant also calls tools on the user's behalf, delegated identity flows such as OAuth 2.0 for AI agents keep those calls scoped to the same person.
3. Filter during retrieval
The retrieval query includes a filter built from the user's identity, so the vector database only searches chunks the user can see. Microsoft documents this pattern for Azure AI Search as security trimming: results are filtered by group identifiers stored in the index. Most vector databases support metadata filters or separate namespaces per tenant for the same purpose, as described in Pinecone's indexing documentation.
4. Keep permissions in sync
Access changes constantly. People switch teams, folders get reshared and projects close. A production system needs a sync job, or event-driven updates, that refreshes access metadata and removes chunks when source documents are deleted or restricted.
Pre-filtering vs post-filtering
There are two common ways to apply permissions, and the difference matters.
Pre-filtering restricts the search space before similarity ranking. The user only ever competes against chunks they can access, so results stay relevant and nothing forbidden is retrieved. This is the safer default.
Post-filtering retrieves the top results first and then drops anything the user cannot see. It is easier to bolt on, but if most top results are forbidden the user may get few or no useful chunks, and forbidden content has already passed through your application.
Some teams add a final check: before showing a citation, the application verifies live against the source system that the user can still open that file. That catches permission changes the last sync missed.
Design decisions AI engineers have to make
Granularity: is access defined per document, per folder, per record or per field? CRM and HR data often need row-level or field-level rules, which may call for querying the source system directly instead of indexing everything.
One index or many: separate indexes or namespaces per tenant give strong isolation; shared indexes with metadata filters are cheaper but need careful testing.
Group expansion: nested groups in an identity provider must be resolved correctly, or users get either too much or too little access.
Caching: any cache of answers or retrieved chunks must be keyed by user or permission set, not only by the question.
Sensitive fields: even inside allowed documents, some data such as personal identifiers may need masking before it reaches the model.
How to test that access control actually works
Permission bugs are silent. The assistant gives a confident, helpful answer and nobody notices it came from a document the user should not see. That is why access control deserves its own evaluation set:
Create test users with different roles and a set of documents with known permissions.
Write questions whose correct answer only exists in a restricted document, and assert that low-privilege users never receive it or its citation.
Revoke access to a document and confirm it stops appearing after the next sync.
Log the user ID, applied filter and retrieved chunk IDs for every request so you can audit what happened.
Running these checks on every deployment turns "we think it is secure" into evidence you can show a client's security team.
Where this fits in the forward deployed role
Forward deployed AI engineers work inside real organizations with messy permissions across many tools. Connecting an LLM to company knowledge is the easy part; the work that earns trust is mapping how access works today, preserving it in the AI system and proving it holds. That combination of retrieval, identity and data governance is what separates a demo from a system a company lets every employee use.
FAQ
Can't I just tell the model not to reveal confidential information?
No. Instructions in a prompt can be ignored or bypassed, for example through prompt injection. Access control has to happen in retrieval and in your application code, before the data reaches the model.
Does permission-aware RAG make answers worse?
It can make some answers less complete for users with limited access, which is the intended behavior. With pre-filtering, relevance among allowed documents stays high.
Is this only for large enterprises?
Any organization that indexes more than public content needs it: a startup with HR files, customer contracts or multiple clients in one product faces the same risk.
Keep learning with Coderhouse
Building retrieval systems that respect enterprise permissions is part of deploying AI where it matters. The Forward Deployed AI Engineering Course is designed for software engineers and backend developers comfortable with Python: eight weeks with one 2-hour live online class per week and about 6 to 8 hours of work weekly. Explore the paths that fit your goals:
Forward Deployed AI Engineering Course — build, integrate and hand off production AI systems, including secure retrieval over company data.
Data Analytics Course — learn SQL, Python and experimentation to understand and measure the data your AI systems use.
GTM Engineer Course (waitlist) — join the waitlist for early access to the program focused on building modern go-to-market systems.
I'm Dan Patiño, head of AI Strategy & Innovation at Coderhouse. My day-to-day work involves merging the tactical management of e-commerce (CRO, Email Marketing and SEO) with the development of disruptive solutions. I specialize in building internal AI-powered apps to automate tasks and boost innovation within the team. I firmly believe that technology is strategy's best ally. To dive deeper into my professional journey, I'll be waiting for you on my LinkedIn profile.