Citation patterns
Making grounded answers auditable: source IDs, verbatim quotes, and the mechanical check that catches hallucination in the act.
A grounded answer without citations asks to be trusted; a cited answer can be checked. In Foundations you learned to verify claims by hand. Now you're the engineer — you design the output so verification is mechanical.
The pattern: IDs + verbatim quotes
<context>
[S1] Returns are accepted within 30 days of delivery in original packaging.
[S2] Damaged items: photo required; replacement ships within 2 business days.
[S3] Holiday orders (Nov 15–Dec 24) may be returned through January 31.
</context>
Return ONLY JSON:
{
"answer": string,
"citations": [ { "source_id": "S1"|"S2"|"S3", "quote": string } ],
// quote must be COPIED VERBATIM from that source — no paraphrase
"answerable_from_context": boolean
}
Every factual claim in `answer` must have a citation. If context is
insufficient, set answerable_from_context false and say what's missing.Why verbatim quotes are the trick
The quote field isn't decoration — it's a hallucination tripwire you can check without any AI. The test is just: does this exact text appear in the cited chunk? A model can hallucinate an answer and it reads fine; hallucinating a verbatim quote that actually exists in the source is nearly impossible. Failed quote check → the claim gets flagged before a human ever relies on it. It's a plain "does this exact text appear?" check — Ctrl-F for you, one line of code for a developer.
- Number your chunks (
[S1]…) when assembling context — IDs make citations unambiguous and diffable across runs. - Require a citation per claim, not per answer. One citation on a three-claim answer means two claims are free-floating.
- Watch citation-shaped confabulation: a real source ID attached to a claim that source doesn't support. The quote requirement catches this — the quote either won't exist or won't support the claim when a human spot-checks.
- Surface citations to end users when trust matters. 'Per our returns policy (S1): …' converts an AI assertion into a document lookup.
Using the three-source context and schema from this lesson, answer: "My order from December 20th arrived scratched — can I still return it, and what do I need to do?" Then verify each quote by hand against the sources. Does every claim in the answer trace to a citation? Which source *should* have been cited twice?
The right answer needs S2 (damage/photo) AND S3 (holiday window) — a two-source synthesis with clean citations. If your run cited only one, tighten the 'citation per claim' wording and re-run.
Quote-and-verify is how serious AI products earn trust — legal research tools, medical scribes, the analytics agent course's guardrails, and our own products' explainable outputs all rhyme with it. Design for auditability and the trust conversation gets easy.