How Would You Design Company Document Q&A?
How to design a Q&A tool over company files: indexing, permissions, answers with citations and tests, explained for your AI interview.
In short
Index the company's files with the groups allowed to read each one. For each question, keep only the passages the asker may open, then have a model answer from them with citations. Permissions are enforced in the search, before the model sees any passage.
13 min readIntermediateVery common · estimateFacts checked 26 November 2026
Say it out loud
Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.
A company document Q&A tool answers staff questions from the company's own files. I would split each file into passages and index them with the groups allowed to read them. When someone asks, a permission filter keeps only the passages that person can open. The model then answers from those passages and cites each one. Access is checked inside the search, before any text reaches the model, and I would test with real questions before launch.
I would start with the files, not the chat box. Take a legal team with forty thousand supplier contracts. Each file is read on a schedule and whenever it changes, split into passages, and stored in a search index. Each passage keeps the groups allowed to read that passage. That is plain data work, and everything else depends on it.
Then a question arrives. A lawyer asks which deals can be ended if the supplier is sold. Before any model sees text, a permission filter keeps only the passages her groups can open. The search uses both meaning and exact words, because a clause number like 14.2 is an exact match. The best passages then go to the model, which writes the answer from them only.
Access checks belong inside the search itself. A line in the prompt saying to share only what the user may see is not a control, because the model has already read the forbidden text by then. OWASP's 2026 guidance says to enforce scoping inside the index query, not as a filter after retrieval, and Microsoft's security filters trim results to a group string that the app has already checked.
Every answer shows citations to the passages it used, so the lawyer can check the clause herself. Before launch I would test with real questions from the team and check the filter with users from different groups. Old versions and removed access are the usual failures, so the index has to sync on every change.
What is document Q&A, in plain words?
A company document Q&A tool lets staff ask a question in plain English and get an answer taken from the company's own files: contracts, policies, handbooks and price lists. Behind the chat box, the tool finds the right passages first, then has an AI model write the answer from them and say where each fact came from.
Three things make it hard. The files must be searchable. Each person may only see the files they are cleared to open. And every answer must point back to its source, so someone can check it.
Think of a solicitor's clerk in a large firm's file room. The clerk pulls files for a lawyer, but only the ones that lawyer is cleared to open, then writes a short note with page references. A clerk who hands over the wrong file has leaked it, even when the note is perfect.
Take a legal team with forty thousand supplier contracts. A lawyer asks which deals can be ended if the supplier is sold. The answer must use only the contracts she can open, and it must name the clause it used.
Key words
- Chunk
- A passage cut from a file, small enough to search and to hand to the model.
- Index
- A search store that finds passages by meaning and by exact words.
- Permission filter
- A check that drops any passage the asker's groups cannot open.
- Citation
- A pointer from a claim in the answer to the passage it came from.
How does the pipeline work?
It has two halves. Ingest runs on a schedule and whenever a file changes. It reads the file, splits it into passages, and stores each passage in the index with the groups allowed to read that passage. Answering runs for every question. It searches the index, keeps only the passages the asker may open, gives those to the model, and shows the citations.
Company document Q&A, end to end
Ingest, on change
Contracts and policies
each file lists who may read it
Split into passages
each passage keeps its groups
Search index
meaning and exact-word matches
Answer a question
Question from a lawyer
groups come from the login system
Filtered search
only passages her groups can open
Model
answers from allowed passages only
Answer with sources
each claim links to its passage
- 1Each file is read and cut into passages.
- 2Each passage is stored with the groups allowed to read its file.
- 3The question reaches the search, and her groups come from the login system.
- 4The index is searched with her groups applied as a filter.
- 5The best passages she can open go to the model.
- 6The model writes the answer, and each claim points to its passage.
- 1
Read and split
Parse each file, keep its page numbers and groups, and cut it into passages.
- 2
Index with groups
Store each passage with its groups, so access can be checked at search time.
- 3
Filter inside the search
Drop passages the asker cannot open, then keep the best matches.
- 4
Answer with citations
The model writes only from those passages and names the one behind each claim.
Why do permissions belong in search, not the prompt?
The tempting fix is a line in the prompt, such as a rule to share only what the user may see. It fails because the model has already read the forbidden text by then. OWASP's 2026 entry on vector and embedding weaknesses (LLM09) puts the check in the query itself. OWASP writes about tenants, and the same rule holds for groups inside one company.
“Enforce tenant scoping inside the index query, not as a post-retrieval filter, and validate it server-side.”
OWASP, LLM09:2026 Vector and Embedding Weaknesses
“Foundry IQ (Azure AI Search) supports creating a filter that trims search results based on a string containing a group or user identity.”
Microsoft, security filters in Foundry IQ (Azure AI Search)
Microsoft's filter works this way: each passage carries a string for the identities allowed to read it, and the search trims results to the group string the app passes in, after the app has checked the user. Microsoft presents this pattern for systems that cannot use built-in document-level access lists, so first check what your search platform offers natively. OWASP also says to set access at the chunk level, because a mostly-public document can hold one confidential paragraph. It also warns that in multi-tenant deployments, search often runs across everything before access control is applied, and that a probing attacker can learn about files they cannot open. A scope sent by the client is only a suggestion, so the groups must come from the server's own identity system.
Where the permission check sits
Rule in the prompt
Top results are sent
including the bonus file
Filter before the model
Forbidden passages dropped
based on the asker's groups
Leak is possible
one clever question can pull it out
Nothing forbidden is sent
the model cannot leak what it never saw
- 1The model reads the bonus file, and a clever question can get it repeated.
- 2Only passages the asker may open reach the model.
Here is a made-up search over four company documents, with the filter first. Each person sees only what their groups allow.
# A made-up legal search over four company documents. Real systems use a search index; the rule is the same.
DOCS = [
{"id": "MSA-114", "groups": {"legal-emea"}, "text": "Change of control means the supplier may end this agreement."},
{"id": "MSA-220", "groups": {"legal-us"}, "text": "Change of control needs written notice within 30 days."},
{"id": "NDA-031", "groups": {"legal-emea", "sales"}, "text": "Confidentiality lasts five years after the end date."},
{"id": "BON-007", "groups": {"hr-exec"}, "text": "Change of control bonus for the executive team."},
]
def search(question, user_groups, k=3):
# Permission filter first: a passage the user cannot open is never scored or sent on.
visible = [d for d in DOCS if d["groups"] & user_groups]
words = set(question.lower().split())
def overlap(d):
return len(words & set(d["text"].lower().split()))
ranked = sorted(visible, key=overlap, reverse=True)
return [d["id"] for d in ranked if overlap(d) > 0][:k]
print(search("change of control", {"legal-emea"}))
print(search("change of control", {"legal-us"}))
print(search("change of control", {"hr-exec"}))Output
['MSA-114'] ['MSA-220'] ['BON-007']
Notice the order. The filter runs before anything is ranked, so a forbidden passage is never scored, never shown and never sent to the model. The same question gets three different answers for three people, and that is the intended behaviour.
What breaks at scale, and how do you fix it?
Meaning search and keyword search each miss things. Meaning search finds clauses about ending a deal, but Anthropic's post on contextual retrieval says embedding models can miss exact matches that matter, such as an error code. A clause number or a contract ID is the same kind of exact match. Keyword search (BM25) does well on queries with unique IDs or technical terms, so a contract ID like MSA-114 is a good test for it.
Stale files
An old policy answers with last year's rule. Fix: version each file and drop the old copy from the index when a new one lands.
Access that changes
Someone moves teams but still sees passages. Fix: sync groups from the identity system often, and deny when unsure.
Text that gives orders
A vendor's PDF hides a line telling the model to ignore its rules. Fix: treat passages as data, never as orders, and keep send and pay tools behind code checks.
Broken parsing
Scanned pages and tables lose their structure. Fix: sample each file type after parsing, before it is indexed.
The third item is prompt injection in a new place. OWASP's 2026 entry on prompt injection lists a retrieved passage as one route for it, so a passage from the index is never automatically trusted.
Tip
Give the model a way to say it does not know. An answer that says the files do not cover this is safer than a confident guess.
Every answer should show its sources. Anthropic's citations feature is built for this, and its docs describe the aim in plain words:
“Citations return the exact passages that support each claim, so you can verify answers and surface sources to your users.”
Anthropic, citations
OpenAI's file search can also filter on each file's metadata, so a team can narrow a search to one contract type.
How would you handle a contract replaced yesterday?
A supplier signs a new version of its contract, and the old file is removed from the shared drive. Until the index catches up, the old clause still answers questions, and a lawyer may act on it.
- Weak
Nightly rebuild only
Answers can quote a removed contract for up to a day.
- Better
Sync on every change
Each change updates or deletes the passages soon after it happens.
I would also keep a version number on every passage, so an answer can say which contract version it used. Deletes need a test of their own: remove a test file and check that it no longer answers.
What does the interviewer want to hear?
A strong answer covers
- Clarify the users, the files and the access rules before any design.
- Two halves: ingest on change, and answer per question.
- Access checked inside the search, before the model sees any passage.
- Citations on every answer, and an honest reply when the files do not say.
- Sync on change for deletes and access, with a version on each passage.
- Tests on real questions, plus a check that each group sees only its files.
Common traps
Trap"Put the rule in the system prompt and you are done."
BetterThe model can be talked around. Enforce the rule in search, where code decides.
Trap"Vector search finds everything."
BetterMeaning search misses exact clause numbers and codes. Combine it with keyword search.
Trap"Just paste all the contracts into the prompt."
BetterForty thousand contracts are far more text than one prompt holds, and it would show everyone everything.
Can you spot the leak?
Spot the leak
Which retrieval step stops a junior analyst from reading the salary file?
Quick check
A contract is deleted at 9 am. Which change stops old answers quoting it soon after?
Can you answer these from memory?
Flash cards · tap a card to flip it
What will they ask next?
- Q140How do you enforce access control in RAG?11 min
- Q352Design a work copilot that never leaks data the user can't access.Coming soon
- Q123What is hybrid search (BM25 + vectors)?11 min
- Q139How do you keep the index fresh?11 min
- Q135How do you add citations?11 min
- Q354What are the multi-tenant concerns?Coming soon
Learn it in depth
Last updated on 26 November 2026
Building a Q&A tool over your company's documents?
I design and build AI systems like this one: the search, the permission rules, the citations and the tests. Book a short call and tell me what your files and access rules look like.