Retrieval-Augmented Generation (RAG) · Lesson 6 of 7
Grounded generation and citations
Generate answers from retrieved evidence and verify citation references.
Lesson
After retrieval, construct a compact context that keeps each passage associated with a stable source identifier. Tell the model to use those passages as evidence, cite the identifiers that support its statements, and report when the context does not answer the question. Avoid passing unnecessary personal or confidential fields into the prompt. If the evidence is contradictory or stale, the answer should surface the limitation instead of blending claims into false certainty.
Validate citations in application code against the actual retrieved set and preserve links or source locations for the user. Citation presence alone does not prove a claim is supported, so review whether the cited passage entails the answer.
The generation step should receive a compact set of passages with stable source IDs and clear boundaries. Instruct the model to answer only from those sources, cite the IDs supporting each claim, and say when evidence is missing. Validate citations against the passages actually retrieved; a plausible but nonexistent ID is still a false citation. Distinguish a direct quotation from a paraphrase and avoid claiming stronger certainty than the source supports. If sources conflict, define whether the application should prefer newer material, surface the disagreement, or route the question for review.
Implementation drill: trace one representative request through the stages in the diagram. Write down what enters each stage, what output or evidence it produces, and which identity is allowed to perform it. Then test an empty input, an unauthorized request, a dependency timeout, and an unexpected result. For each case, state whether the application should retry, reject, abstain, or ask a person for help. Keep the observed failure as a regression example so changes to prompts, models, data, or code can be checked against the same behavior.
Practice task: What should happen when retrieved context does not support an answer?
Visual guide
Generate an answer supported by sources
-
Step 01
Context
Supply bounded passages with source IDs.
-
Step 02
Answer
Generate only claims supported by evidence.
-
Step 03
Verify
Check citations against retrieved sources.
-
Step 04
Abstain
Escalate when evidence is insufficient.
Key points
- Preserve source IDs when building the model context.
- Ask for evidence-based answers and an explicit insufficient-evidence response.
- Validate citation IDs and assess whether citations actually support claims.
Check your understanding
Practice
Your learning progress