RAG Systems · Answer Quality · lesson 6 of 8
Citations and grounding
about 18 minutes · free · runs in your browser
An answer you cannot check is a rumour
A grounded system says where each claim came from. Not for decoration: a citation is what lets a reader verify the answer, and what lets you find the bad chunk when the answer is wrong.
The mechanism is simple — number the passages in the prompt and require the model to cite by number.
[1] Refunds are processed within 30 days.
[2] Shipping takes 3 to 5 working days.
Cite the passage number for every claim, like this: [1].
Then verify the citations you get back. A model can cite [4] when three passages
were provided, and a citation pointing at nothing is worse than none at all — it looks
checkable and is not.
Your turn: write number_passages(passages) producing the numbered block, and
valid_citations(answer, count) returning the cited numbers that actually exist,
in the order they appear, without duplicates.
You start from this, and edit it in the browser:
import re
def number_passages(passages):
"""Return the passages as a numbered block, one per line, starting at [1]."""
return ""
def valid_citations(answer, count):
"""Return the cited numbers that exist, in order, without duplicates."""
return []