Citations & Sources
Every answer with its receipts
Citations turn RAG from a claim machine into an evidence machine. Design the citation format, verify them, and make them appear in the UI in the right places.
What you will learn
- Design chunk-id citation format
- Verify citations point at real content
- Render citations in UI and APIs
What is this?
Citations are the visible contract of grounding: each substantive claim carries the chunk id (ultimately a document link) that supports it. A citation system includes format (inline tags per sentence), verification (is the id real and containing?), and rendering (clickable footnotes in chat, structured metadata in APIs).
Why do you need it?
- Users must be able to check any claim — trust compounds.
- Citations double as a debugging joystick: wrong citations are retrieval+verify signals.
- Structured citations make downstream integrations AGREEABLE (CRMs, ticketing).
- Verification converts 'the model said' into 'the source says'.
Mental model
A bibliography next to a research claim
RAG citations
A paper's vital first claim without a footnote gets challenged in review. Here every paragraph cites the exact chunk it rests on — not 'see whole library' but this page, this section, so a reader can flip to it and confirm.
How it works
- Chunks carry stable ids and source metadata (doc, path, heading).
- Prompt: 'End every claim with the id of the chunk that supports it.'
- Parse the response for [id] markers; check each against the retrieved list.
- Reject or re-send when citations reference unretrieved/fabricated ids.
- Render: footnotes with links in chat; structured attribution objects in APIs.
Citation round trip.
In production
- Support answers show which help-center page backs each step.
- API responses include sources[] with docUrl, chunk, score for downstream legal flows.
- Internal tools tint text by citation validity (good/bad link).
Best practices
- Use a reserved marker format the model reliably emits (e.g. [1], <cite path=…>).
- Verify every cited id: it must be in the retrieved set AND its text contains the claim.
- Fall back to 'no citations' styling rather than showing unverified links.
- Store citations with the answer for eval and audit.
Common mistakes
- No format: the model emits 'source' as free text you can't verify.
- Showing citations that never get verified — fake receipts.
- Splitting claims across chunks and citing only one.
- Losing citation structure when chat history compacts.
Common issues
Fabricated citation idsModel invents markers outside the retrieved set
Post-validate membership; provide the available ids explicitly to the model.
Users click citations that don't matchVerification missing or source metadata wrong
Containment-check each citation; fix source-metadata mapping.
Debugging tips
- Citations to unretrieved ids = marker hallucination; enforce set membership.
- Citations correct but wrong doc = reranker/retrieval confusion, not formatting.
- Model refuses to cite = prompt tension (tone over rules); record and report.
Interview checkpoint
Hands-on lab
- Generate answers with chunk-id markers
- Verify markers against the retrieved set
- Deliver ungrounded answers to a review path
Verifiable Citation Flow
35 min · intermediate
Quick quiz
A trustworthy citation must be…
Showing citations without verification is harmless.