C.W.K.
Stream
Lesson 05 of 10 · published

Citing Sources Inside the Prompt

~14 min · context, citations, grounding

Level 0Apprentice
0 XP0/100 lessons0/14 achievements
0/120 XP to next level120 XP to go0% complete

If the model can't cite, the user can't trust

An ungrounded answer is a confidence trick. When a user can verify which chunk a sentence came from, two things happen: hallucinations are detectable (the cited chunk doesn't say it), and the user's trust calibrates correctly. Citations are not decoration; they are the verifier.

The shape

Each chunk gets a stable id in the prompt (like chunk-7, or a real document_id). The synthesis prompt requires every factual claim to end with a bracketed id. If multiple chunks support the claim, list multiple ids. If no chunk supports it, the model must mark it explicitly.

Native citations

Anthropic's Citations feature returns structured citations alongside the response, mapping spans of output to spans of input. OpenAI and Gemini handle this at the application layer. Use the structured feature when available; fall back to bracketed ids otherwise.

Code

Citation-required synthesis prompt·markdown
# System
Answer using only <context>.
Every factual claim must end with [<chunk-id>] referencing a chunk in <context>.
If no chunk supports a claim, prepend "Unverified: " to the sentence.

# User
Question: {{q}}

<context>
[chunk-1] ...
[chunk-2] ...
[chunk-3] ...
</context>

External links

Exercise

Add bracketed-id citations to a RAG synthesis prompt. Write a programmatic verifier that flags any sentence whose citation doesn't actually appear in the cited chunk.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.