16 November 2026, 7 min read
AI knowledge base: how to give agents your company's knowledge without leaking what they shouldn't see
An AI knowledge base is only safe if retrieval respects permissions. Here is how permission-aware RAG works and where it usually goes wrong.
An AI knowledge base sounds simple: put your company's knowledge somewhere and let AI tools answer questions from it. The part that goes wrong is the word "your". Company knowledge is not one pool with one audience. It is salaries and org charts, board notes and handbooks, customer contracts and public pricing, all mixed together, with different people allowed to see different parts.
An AI tool that ignores that mix is a data leak with a friendly interface. This post sets out how leaks happen, what permission-aware retrieval means in practice, and a checklist for testing your own setup.
How the leaks actually happen
Most failures follow a small number of patterns.
The broad connector. Someone connects an AI tool to a wiki or drive using an administrator's credential, because it is the easiest way to get everything indexed. The index now contains everything. Any employee who can query the tool can reach any of it.
The post-hoc filter. The system retrieves broadly, hands the results to the model and asks it to leave out anything the user should not see. By that point the restricted text is already in the prompt. The model may follow the instruction, and it may not.
The prompt as policy. A system prompt says "never reveal salary information". That is a request to a probabilistic system. OWASP's guidance on sensitive information disclosure notes that restrictions in a system prompt may not always be honoured and can be bypassed by prompt injection. The same page recommends limiting access to sensitive data on a least-privilege basis, which is the principle the rest of this post builds on.
The indirect hint. Even when the content is filtered, the answer can reveal that something exists. "I cannot show you the restructuring plan" tells the asker there is one. An unauthorised record should look the same as a missing one.
What permission-aware retrieval means
Retrieval-augmented generation, described in a 2020 paper by Lewis and colleagues, has two steps: a retriever finds relevant passages, and a model answers using them. Permission-aware RAG adds a rule about the first step. The retriever may only return what the asker is entitled to read.
That sounds like a filter, but where it happens matters.
| Approach | Where access is checked | Failure mode |
|---|---|---|
| Instruct the model | In the prompt | Model ignores or is tricked into ignoring the rule |
| Filter the answer | After generation | Restricted text already influenced the output |
| Filter the results | After retrieval, before the prompt | Better, but ranking and counts can still carry hints |
| Retrieve only entitled records | Before ranking | Restricted records never enter the pipeline |
The last row is the target. If a record is not visible to the asker, it should not be a candidate at all. It should not be scored, it should not be counted and it should not take up a slot that changes what else is returned.
NIST's guide to attribute-based access control describes the underlying idea: decide whether a user may perform an action by comparing attributes of the user, the resource and the context against policy. You do not need a particular standard to get this right. You need one policy, evaluated in one place, that every read path uses.
If the model has seen it, assume the asker can get it. The only reliable place to say no is before the model.
Whose access does an agent get?
This is the decision that shapes everything else. There are two reasonable answers, and one common wrong one.
The agent acts for a person. A person connects Claude, ChatGPT or Cursor to the knowledge base. The tool then sees exactly what that person can see, no more. This is the right default for assistants that answer questions.
The agent acts for a team or a process. A scheduled agent that drafts a weekly summary has its own identity, with a deliberately narrow scope. It is granted what it needs and nothing else, and it is revoked when it stops being useful.
The agent acts as an administrator. This is the wrong answer, and also the easiest to set up. It converts every question into an administrator's question.
MCP, the open protocol most AI tools use to connect to external systems, defines servers that expose tools, resources and prompts to a client. It describes the connection, not the policy. Whether the server applies the asker's permissions is a decision the server's author made, so it is worth asking directly.
Why ranking can leak too
Filtering results after ranking looks safe and is not quite. Suppose a retriever scores every record, takes the top ten and then removes the ones the asker cannot see. Two things have happened. The asker may get six results instead of ten, which tells them four relevant records exist. And if scores are relative, such as a rank among all candidates, an allowed record's position can depend on how many restricted ones outranked it.
The fix is to decide who is a candidate before anything is scored. Relevance then depends only on the record and the query, and never on what else the asker is not allowed to see. It is a small design choice with a large effect, and it is cheap to get right at the start and painful to retrofit.
A checklist for your own setup
You can test most of this in an afternoon.
- List the sensitive fields. Salary, performance ratings, legal notes, security findings. Write them down.
- Create two test users. One who may see the sensitive material, one who may not.
- Connect an AI tool as each. Use the same tool and the same configuration.
- Ask the same direct questions. "What does Sam earn?" Compare the two answers.
- Ask indirect questions. "Who is the highest paid person in engineering?" "Summarise everything about the restructuring." The restricted user should get an answer that reads as though the restricted material does not exist.
- Check citations and snippets. Titles, previews and error messages can leak as easily as the answer.
- Change the access and ask again. Remove the first user's access and confirm the next answer changes immediately.
- Check other paths. Search, export, the API and the CLI should all enforce the same rule as the web interface.
If any step fails, you have found it before a real user did.
Writes are part of the same problem
Reading is half the story. Agents increasingly write: updating a field, adding a record, correcting a date. Two risks follow.
First, an agent should not be able to change anything its person could not change. Write scope should follow the same rule as read scope.
Second, an agent's write should not silently replace a person's. We think the right behaviour is a proposal: the new value is recorded with its source, and the owner of the record accepts or rejects it. We go into that in when AI and people disagree.
Sharing is another place where AI help can overreach. An assistant that suggests "this page should be visible to the whole company" is useful. One that applies the change on its own is a leak you authorised by accident. Suggestions should come with a preview of exactly what would become visible, and a person should approve it.
Where the data comes from
Permission-aware retrieval depends on knowing the owner and audience of every record. That is hard to retrofit onto a pile of PDFs. It is easier when content enters a system that has records and access rules from the start: uploaded files, a read-only database connection or an MCP server, each landing in a collection with an owner and a default of private.
The default matters more than it looks. If new content is shared with everyone until someone remembers to restrict it, restrictions will lag behind the content. If new content is private until someone shares it, the failure mode is an annoyed colleague asking for access, which is a much better problem to have.
For a longer look at how the shape of a knowledge base affects what agents can do with it, see corporate wikis vs company knowledge bases.
How Contextely approaches this
Contextely treats access as part of retrieval, not a layer on top. Everything is private by default. Sharing goes to people, teams or everyone, and permissions apply to fields as well as records. AI tools connect over MCP, a CLI or a REST API, and each sees exactly what the person it acts for can see.
Content arrives through sources: drag-and-drop upload of PDF, DOCX, Markdown and CSV, a read-only Postgres connection, or any MCP server. AI-suggested sharing is never applied on its own; a person approves an exact preview first. Administrators cannot read restricted data such as salaries by default. They can make a logged break-glass request, and the owner is notified.
The short version
Do not rely on a model to keep secrets. Decide whose access each agent carries, enforce it before retrieval, treat unauthorised records as missing and test with two users who should see different things. An AI knowledge base earns trust by what it declines to return.
Questions
What is an AI knowledge base?
A company knowledge base that AI tools can read, typically through retrieval. The useful version enforces the same access rules for an AI tool as for the person it acts for, so the tool cannot surface anything that person could not open.
What is permission-aware RAG?
Retrieval-augmented generation where access is checked before anything reaches the model. The retriever only considers records the asker is entitled to, so unauthorised content never appears in the prompt and cannot be summarised, quoted or leaked.
Is a system prompt enough to stop an agent revealing secrets?
No. A system prompt is an instruction to the model, not a control. It can be ignored or bypassed through prompt injection. Access has to be enforced in the retrieval layer, before the model sees the data.
Should AI agents use a service account?
Avoid it for anything that answers questions for people. A broad service account means every asker inherits its reach. Give each agent the access of the person it acts for, and scope any autonomous agent to the minimum it needs.
How do I test that an AI knowledge base does not leak?
Create two test users with different access, ask both the same questions, including ones that probe for restricted data, and compare the answers. Also check that the restricted records do not appear in citations, snippets or error messages.