# 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.

AI and LLM interview question Q348, LLM system design. Intermediate, very common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/design-company-document-qa

## Say it in 30 seconds

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.

## Say it in 2 minutes

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.

- **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.

*Diagram, Company document Q&A, end to end: Files are split and indexed with their access groups kept on each passage. For each question, the search applies the asker's groups as a filter, so only passages she can open come back. The model answers from those passages, and each claim points to one of them.*
1. Each file is read and cut into passages.
2. Each passage is stored with the groups allowed to read its file.
3. The question reaches the search, and her groups come from the login system.
4. The index is searched with her groups applied as a filter.
5. The best passages she can open go to the model.
6. The 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.

*Diagram, Where the permission check sits: Two designs, one above the other. A rule in the prompt lets the top results reach the model, forbidden ones included, so a clever question can pull one out. A filter in the search drops forbidden passages first, so the model never sees them.*
1. The model reads the bonus file, and a clever question can get it repeated.
2. Only 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.

```python
# 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:

```text
['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." Better: The model can be talked around. Enforce the rule in search, where code decides.
- Trap: "Vector search finds everything." Better: Meaning search misses exact clause numbers and codes. Combine it with keyword search.
- Trap: "Just paste all the contracts into the prompt." Better: Forty 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?

A. Add to the system prompt: never show salary data.
B. Search every passage, then ask the model to skip salary data.
C. Filter the search on the asker's groups, so only allowed passages come back.
D. Use a larger model, which follows rules more reliably.

**Answer:** C. Only a filter in the search keeps the salary passages away from the model. The prompt and the model's size can be talked around, so neither is a control.

**Quick check:** A contract is deleted at 9 am. Which change stops old answers quoting it soon after?

A. A longer system prompt
B. Sync deletes and access changes into the index on every change
C. A bigger chunk size
D. A lower temperature

**Answer:** B. A delete must reach the index on change, or old passages keep answering. Prompt length, chunk size and temperature remove nothing from the index.

## Can you answer these from memory?

**Flash cards**

- **What are the two halves of the pipeline?** Ingest, which indexes files on change, and answering, which runs for each question.
- **Where should permissions be enforced?** Inside the search query, before the model sees any passage.
- **Why keep groups on each passage?** So the filter can drop passages the asker cannot open, at search time.
- **Why add keyword search?** Meaning search can miss exact clause numbers and codes. Keyword search catches them.
- **What is a citation here?** A pointer from each claim in the answer to the passage behind it.
- **What breaks answers after a change?** Stale or deleted files still in the index, so old clauses keep answering.

## Likely follow-up questions

- Q140 How do you enforce access control in RAG? https://designervenkat.online/interview/ai/how-do-you-enforce-access-control-in-rag
- Q352 Design a work copilot that never leaks data the user can't access. (full answer coming)
- Q123 What is hybrid search (BM25 + vectors)? https://designervenkat.online/interview/ai/what-is-hybrid-search
- Q139 How do you keep the index fresh? https://designervenkat.online/interview/ai/how-do-you-keep-the-index-fresh
- Q135 How do you add citations? https://designervenkat.online/interview/ai/how-do-you-add-citations
- Q354 What are the multi-tenant concerns? (full answer coming)

## Learn it in depth

- [RAG & Dynamic Filters](https://designervenkat.online/learn/ai-engineering/rag-and-dynamic-filters)
- [Unauthorized access](https://designervenkat.online/learn/ai-guardrails/unauthorized-access)
