esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

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.

11 min readIntermediateCommon · 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 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.

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.

Key words

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

How a cited answer is built

Adjuster's question

Is burst pipe damage covered?

Search returns passages

Clause 4.2, 2026

current wording, with an ID

Clause 4.2, 2019

retired wording, still indexed

Model

tags each claim with an ID

Code checks each tag

ID is real, quote is in it

Answer with clause links

adjuster opens the exact clause

  1. 1The question goes to the search first.
  2. 2Search returns passages with IDs, and an old clause can come back too.
  3. 3The model writes the answer, tagging each claim with the ID it used.
  4. 4Only claims that pass the code check reach the adjuster, with their clause links.
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.

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.

Two checks on every citation

A claim with a tag

ID plus a quote from that passage

Checked in code

Was the ID retrieved?

refuse IDs the search never gave

Is the quote in it?

word for word in that passage

Drop the claim

or mark it unsupported

Keep, with its link

both checks passed

  1. 1The model's claim arrives with its tag and its quote.
  2. 2If either check fails, the claim is dropped or marked unsupported.
  3. 3A claim that passes both checks is shown with its link.
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.

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

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

    Store the date

    Every passage carries its effective date when it is indexed.

  2. 2

    Filter at search

    Retired wording never enters the prompt.

  3. 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."

    BetterIt 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."

    BetterA prompt is a request. Use the platform's citation feature where there is one, and still check the result.

  • Trap"Link the whole document."

    BetterA 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?

Quick check

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

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q131Retrieval metrics: recall@k, MRR, nDCG?12 min
  2. Q132Generation metrics: faithfulness, answer relevance?10 min
  3. Q133What are common RAG failure modes?11 min
  4. Q134How do you reduce hallucinations in RAG?13 min
  5. Q139How do you keep the index fresh?11 min
  6. Q140How do you enforce access control in RAG?11 min

Learn it in depth

Last updated on 26 November 2026

Building an assistant that must show its sources?

I design and build AI products and agents, including the citations and checks behind them. Book a short call and tell me what your documents are and who reads the answers.