AI that respects permissions
RAG and MCP tools with permissions inside the search, not after it: the model never decides who may read what.
Abstract
Almost every company's first internal assistant puts all its documents into one vector index, gives the model tools with a service account and lets everyone ask. Each part looks reasonable; together they break the most basic rule of information security, that people only see what they are allowed to see. EnterpriseRAG is our self-hosted reference implementation of the opposite pattern: permissions are resolved by the backend on every request, applied inside the vector query, and they also decide which tools exist for the model and which models may see each piece of data. Unlike the other blueprints on this page it is built and measured; the figures come from its test suite and its evaluation, not from an estimate.
The problem
Ask a naive assistant "What is the salary band for a senior engineer?" and the nearest chunks are the HR salary table, whoever asks. Filtering after the search fails both ways: forget the filter in one code path and the data leaks; find that the top results were all forbidden and nothing is left. ACLs copied into the index go stale, so removing someone from a group does not remove their access until the next re-index. Tools run with a service account, so anyone who can talk to the model can talk to the ERP. Every request goes to the same cloud model, payroll included. And a document that says "ignore previous instructions" is read by a model that has tools.
What gets built
- Identity and policy: users, roles, containers classified as public, internal or confidential, and allow-only grants. One function computes effective permissions from PostgreSQL on every request; being an administrator means managing the system, not reading its data.
- Authorized retrieval: the user's containers and restricted documents go inside the pgvector SQL query, over current versions only, and every hit is re-checked before use. Hybrid search (full text plus vectors, rank fusion) with a local cross-encoder reranker.
- Routing by classification: the most sensitive item in the context decides which models may see it. Confidential data only goes to local models (Ollama); if none is available, the request is refused before anything leaves the machine.
- Tools over MCP through a gateway: the model only receives the tools the user may execute, every call is validated and carries a signed 60-second permission context, and the MCP server filters its data by it before reading anything.
- Every retrieved document and every tool result is treated as untrusted data: delimiters are neutralised, and a validator raises the classification to what the data really is.
- An audit trail of every decision (what was retrieved, what was dropped, where each request went, which tool was allowed or refused) and an AES-256-GCM, write-only credential store.
How it works
- Someone asks a question; the backend computes their permissions at that moment, never from a copy in the index.
- The question is embedded by a local model (bge-m3) and the search only returns chunks the person can already read.
- The highest classification across the context, the history and every tool result sets which models may answer; if it rises mid-conversation, the conversation moves to a local model.
- The model answers with citations. The same question gets different answers: the HR manager gets the salary band; the engineer is told it is not in their sources.
- When an administrator removes a role, the next question has already lost access, and earlier confidential answers in that conversation stop entering the prompt.
Result
The tests check what the model is given, not what it says, so they do not depend on its behaviour. A matrix of 6 personas × 8 questions confirms that no canary from an unreadable container appears in any prompt, and 34 tests against real MCP servers cover hidden tools, forged arguments, tampered tokens and injection. The retrieval evaluation (146 questions asked as personas, 247 runs over about 250 documents in Spanish and English) finds no leaks, and hybrid search with the reranker raises abstention on unanswerable questions from 0.31 to 0.96, with recall@8 of 0.966, at a cost of about 1.3 s per search on CPU. On a modest workstation (a 6 GB GTX 1660) a grounded answer from a local 4B model takes 10 to 12 seconds; authorization adds milliseconds and the per-token cost is zero. The limits are written down too: a model can still be wrong, or repeat to an authorized person what it was legitimately given, and the injection filter is heuristic. The guarantees come from the structure, not from the filter.
Want this running on your data?
We start by mapping one of your processes end to end, at no cost. The blueprint comes out of that.