# How Do You Add Citations?

> How an AI answer points to the exact passage behind each claim, and how code checks those pointers, for your AI interview.

**In short:** Give each retrieved passage an ID, have the model tag every claim with that ID and a quote, then check both in code before showing the answer with its source. Some platforms, such as Anthropic's citations feature, can return the citations for you.

AI and LLM interview question Q135, Retrieval-augmented generation (RAG). Intermediate, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/how-do-you-add-citations

## Say it in 30 seconds

A citation is a pointer from an answer to the exact passage that supports it. In a RAG app (retrieval-augmented generation, where the app searches my documents before the model answers), I give every retrieved passage an ID, and I ask the model to tag each claim with that ID and a short quote. Then my code checks two things: the ID was really in the search results, and the quote really sits in that passage. If either check fails, the claim is dropped. That way the user can open the source and see the exact clause.

## Say it in 2 minutes

Citations matter because a RAG answer can look sourced even when it isn't. RAG means the app first searches your documents, then gives the best passages to the model. A citation ties each claim to one of those passages, so a person can check it in seconds. A claim that can't be traced to a clause is hard to defend in front of a customer.

There are two routes. The first is prompting: I label each passage, then ask the model to tag every claim with that label and a short quote. The second is the platform's own feature. Anthropic's citations feature returns the cited passage with each claim, and OpenAI's file search returns file citations along with the response. The built-in route does more of the work for you, but I still check the output in my own code.

Then I check every tag. For an insurer's claims assistant, a claim that cites the 2019 wording is a serious error, because that clause was retired. So the search keeps only the wording in force on the policy date, and my code refuses any tag the search never returned, and any quote that isn't word for word in its passage. A claim that fails is dropped or marked unsupported, never shown as sure.

Be honest about the limits. A citation shows where a claim came from. It does not prove the model read it correctly. So I still test answers with real claims, and a reviewer signs off anything that touches a payout.

## What is a citation, in plain words?

A citation is a pointer from a claim in an AI answer to the exact passage that supports it. It tells the reader where the claim came from, so they can check it instead of taking the model's word.

In a RAG app (short for retrieval-augmented generation: the app searches your documents first, then gives the best matches to the model), the passages come from your own files, such as an insurer's policy wordings. The citation names the passage, and ideally the words in it that back the claim.

Think of a claims adjuster who writes the clause number beside every decision. The decision letter is only trustworthy because someone can look that clause up.

- **Citation:** A pointer from a claim to the passage that supports it.
- **Chunk:** A piece of a document, cut small enough to search and to fit in a prompt.
- **Passage ID:** A short label, such as wording-2026-4.2, given to each chunk the search returns.
- **Quote:** The exact words copied from the passage that back the claim.

## How do you make the model cite its sources?

There are two routes, and each has a trade-off.

- **Route 1: You prompt for tags.** Label each passage with an ID, then ask for a tag and a short quote after each claim. It needs no special platform feature, but the tags are only as reliable as the model's output.
- **Route 2: The platform returns them.** Some developer interfaces (APIs, the way apps call a model) send back the cited passage with each claim. Anthropic's page lists advantages over prompting for citations, including better citation reliability.
- **Either way: Still check in code.** A tag is a claim too. Your code must confirm it before the user sees it.

> "Citations return the exact passages that support each claim, so you can verify answers and surface sources to your users." (Anthropic)
>
> "Make Claude's response auditable by having it cite quotes and sources for each of its claims." (Anthropic, on hallucinations)

*Diagram, How a cited answer is built: Search hands the model tagged passages, and one of them is retired wording. The model's claims point at those IDs, and code checks each pointer before the answer is shown. Only checked claims reach the adjuster, each with its clause link.*
1. The question goes to the search first.
2. Search returns passages with IDs, and an old clause can come back too.
3. The model writes the answer, tagging each claim with the ID it used.
4. Only claims that pass the code check reach the adjuster, with their clause links.

Anthropic says that if you want Claude to cite specific sentences from your RAG chunks, you should put each chunk into its own plain text document. Anthropic also lets you pass your own search results in, and cites them the same way it cites web search results. OpenAI's file search works from the other side: the model searches your files before it answers, and the response comes back with file citations.

> **Tip:** Asked how you'd add citations? Say you give every passage an ID and check each pointer in code. Don't say the model always cites correctly.

## How does code check a citation?

The model can get a citation wrong in three ways. It can point at an ID the search never returned. It can quote words that aren't in the passage. Or the pointer is real but the passage is out of date. The first two are easy to catch in code. The third needs a date filter before the model reads the text.

*Diagram, Two checks on every citation: Each claim passes two checks in code: the ID was really retrieved, and the quote is word for word in that passage. A claim that fails either check is dropped or marked unsupported. The date filter runs earlier, in the search.*
1. The model's claim arrives with its tag and its quote.
2. If either check fails, the claim is dropped or marked unsupported.
3. A claim that passes both checks is shown with its link.

Here is the check in plain Python. The made-up insurer's assistant gives four claims. The code also refuses retired wording, as a second net. Only the claim that passes every check is kept. The quote test is a shortcut: it needs an exact match, so real code should normalise spaces and quote marks on both sides first.

```python
# A made-up claims assistant's citation check. Each claim names a passage ID and
# quotes it. Code keeps a claim only if its ID was retrieved and its quote is in it.
PASSAGES = {
    "wording-2026-4.2": "Water damage from a burst pipe is covered under section 4.2.",
    "wording-2019-4.2": "Burst pipes are excluded. Storm damage is covered in full.",
}
RETIRED = {"wording-2019-4.2"}

def check(claim):
    passage = PASSAGES.get(claim["cite"])
    if passage is None:
        return "DROP: " + claim["cite"] + " was never retrieved"
    if claim["cite"] in RETIRED:
        return "DROP: retired wording"
    if claim["quote"] not in passage:
        return "DROP: quote not in the passage"
    return "KEEP: " + claim["text"] + " [" + claim["cite"] + "]"

answer = [
    {"text": "Burst pipe damage is covered.", "cite": "wording-2026-4.2",
     "quote": "Water damage from a burst pipe is covered"},
    {"text": "Storm damage is covered in full.", "cite": "wording-2019-4.2",
     "quote": "Storm damage is covered in full."},
    {"text": "A 10% discount applies.", "cite": "wording-2026-4.2",
     "quote": "A 10% discount applies."},
    {"text": "Flood is covered.", "cite": "wording-2026-9.9",
     "quote": "Flood is covered."},
]
for claim in answer:
    print(check(claim))
```

Output:

```text
KEEP: Burst pipe damage is covered. [wording-2026-4.2]
DROP: retired wording
DROP: quote not in the passage
DROP: wording-2026-9.9 was never retrieved
```

## What should each passage carry?

Good citations need good metadata. Each passage should carry enough to find its source again.

- **An ID:** Given by your app, so the model can point at it, such as wording-2026-4.2.
- **The document and section:** The title and clause number, so an adjuster can open the right page.
- **An effective date and version:** So retired wording can be filtered out before the model reads it.
- **A location:** A page number for a PDF, or a character range for plain text. Anthropic's citations feature reports both.

Once a passage has these, a citation can point to a clause, down to the exact section.

### How would you stop a retired clause being cited?

Filter first, then check. The search keeps only the wording in force on the policy date, so a superseded version should never be retrieved. If one slips through, the code is the second net, and the model should never read the 2019 wording.

1. **Store the date:** Every passage carries its effective date when it is indexed.
2. **Filter at search:** Retired wording never enters the prompt.
3. **Check the tag:** The code refuses any claim tied to a retired ID, even if the words match.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: a pointer from a claim to the passage behind it.
- [ ] The two routes: prompted tags, or the platform's citation feature.
- [ ] Code checks every pointer, because the model can still get one wrong.
- [ ] Passages carry IDs, dates and locations, so retired wording can be filtered out.
- [ ] An honest limit: a citation shows where a claim came from. It does not prove the claim is right.

**Common traps**

- Trap: "The model always cites correctly." Better: It can cite the wrong passage or quote words that aren't there. Check every pointer in code.
- Trap: "Just ask for sources in the prompt." Better: A prompt is a request. Use the platform's citation feature where there is one, and still check the result.
- Trap: "Link the whole document." Better: A link to a 90-page policy doesn't show the clause. Point at the passage.

## Can you spot the bad citation?

**Spot the bad citation:** Your claims assistant answered from four passages. Which claim must be dropped?

A. Burst pipe damage is covered. Cites wording-2026-4.2, quote: Water damage from a burst pipe is covered.
B. Storm damage is covered in full. Cites wording-2019-4.2, quote: Storm damage is covered in full.
C. Theft by a household member is excluded. Cites wording-2026-7.1, quote: Theft by a household member is excluded.
D. Glass repair is capped at £500. Cites wording-2026-8.3, quote: Glass repair is capped at £500.

**Answer:** B. Wording 2019 was retired, so it must not back a 2026 claim. The search should filter it by date, and the code should refuse it even when the words match. The other three cite current wording, with their quotes found in the passage. The code above shows two of the four passages.

**Quick check:** A claim has a citation, but the cited passage doesn't contain its quote. What should the system do?

A. Keep the claim, since a citation is attached
B. Drop the claim, or mark it as unsupported
C. Ask the model to reword it more firmly
D. Trust the citation, because models are usually right

**Answer:** B. A citation with no matching quote backs nothing. Anthropic's guidance says the model must retract a claim it cannot support with a quote. Rewording adds no facts, so the claim stays unsupported.

## Can you answer these from memory?

**Flash cards**

- **What is a citation?** A pointer from a claim to the exact passage that supports it.
- **Two routes to citations?** Prompt for tags with IDs, or use the platform's citation feature.
- **What does code check?** That the ID was retrieved, and the quote is word for word in that passage.
- **Why filter by date?** So retired wording is never retrieved, and so never cited.
- **What if a quote is missing?** Drop the claim, or mark it unsupported. Never show it as sure.
- **Is a citation proof it's right?** No. It shows where a claim came from. The model may still have misread the passage.

## Likely follow-up questions

- Q131 Retrieval metrics: recall@k, MRR, nDCG? https://designervenkat.online/interview/ai/retrieval-metrics-recall-at-k-mrr-ndcg
- Q132 Generation metrics: faithfulness, answer relevance? https://designervenkat.online/interview/ai/rag-generation-metrics-faithfulness-answer-relevance
- Q133 What are common RAG failure modes? https://designervenkat.online/interview/ai/common-rag-failure-modes
- Q134 How do you reduce hallucinations in RAG? https://designervenkat.online/interview/ai/how-to-reduce-hallucinations-in-rag
- Q139 How do you keep the index fresh? https://designervenkat.online/interview/ai/how-do-you-keep-the-index-fresh
- Q140 How do you enforce access control in RAG? https://designervenkat.online/interview/ai/how-do-you-enforce-access-control-in-rag

## Learn it in depth

- [Grounded generation](https://designervenkat.online/learn/ai-engineering/generation)
