Quote-then-answer grounding is a two-stage retrieval-augmented generation pattern. In the first stage, the model extracts verbatim quotes from the provided documents that are relevant to the query. In the second stage, it answers the query using only those quotes as evidence.
How it works
Query understanding -- parse the user question to identify key entities and intents.
Quote extraction -- search the provided documents and extract verbatim passages that address the query.
Evidence assembly -- collect the extracted quotes into a structured evidence block.
Grounded answer -- generate the final answer using only the assembled evidence.
When to use
Document Q&A: When answers must be traceable to specific source passages.
Policy compliance: When every claim needs to cite a governing policy document.
Research tools: When users need to verify claims against source material.
Abstention
When no relevant quotes are found in the provided documents, the model should explicitly state that it cannot find supporting evidence rather than hallucinating an answer. This preserves trust and prevents misinformation.
Build This Pattern
Copy this prompt and paste it into Claude Code, OpenCode, Codex, or Cursor to implement this pattern.
Build a grounded Q&A system using quote-then-answer methodology.
ROLE: You are a grounded question-answering system that first extracts relevant evidence from context, then answers using only those grounded snippets.
CONSTRAINTS:
- Two-stage pipeline: extract quotes first, then answer from quotes only
- Answer stage must never introduce external knowledge
- Every claim in the answer must cite a specific source identifier
- If no relevant quotes found, return abstention message instead of hallucinating
- Handle partial relevance, conflicting quotes, and multiple valid answers
TOOL CALLING:
- Use function calling for: extract_quotes(context, question), answer_from_quotes(question, quotes[]), validate_grounding(answer, quotes[]), get_grounding_stats(question_id?)
- Each tool returns structured JSON with grounding data and metadata
STRUCTURED OUTPUT:
- Quote extraction must return JSON: { question: string, quotes: [{ id: string, content: string, source_id: string, relevance_score: number, position: number }], total_quotes: number, coverage_score: number }
- Grounded answer must return JSON: { answer: string, citations: [{ claim: string, quote_id: string, source_id: string }], confidence: number, abstained: boolean, quotes_used: number }
- Grounding validation must return JSON: { valid: boolean, unsupported_claims: [{ claim: string, reason: string }], citation_accuracy: number, total_claims: number, supported_claims: number }
- Grounding stats must return JSON: { total_questions: number, abstained: number, avg_confidence: number, avg_citations_per_answer: number, grounding_accuracy: number }
CHAIN OF THOUGHT:
- Quote extraction: scan context → identify relevant passages → score relevance → return with source IDs
- Answer generation: analyze question → select relevant quotes → synthesize answer → cite sources
- Validation: check each claim against quotes → verify citations → identify unsupported statements
- Abstention: if no relevant quotes → return clear message → explain why → suggest alternatives
FEW-SHOT EXAMPLES:
Context: 'AI agents automate tasks. They work 24/7. Companies report 40% cost reduction.'
Question: 'What are the benefits of AI agents?'
Quotes: [
{ id: 'q1', content: 'AI agents automate tasks', source_id: 'doc_1', relevance_score: 0.95 },
{ id: 'q2', content: 'They work 24/7', source_id: 'doc_1', relevance_score: 0.88 },
{ id: 'q3', content: 'Companies report 40% cost reduction', source_id: 'doc_1', relevance_score: 0.92 }
]
Answer: { answer: 'AI agents provide automation, 24/7 availability, and 40% cost reduction', citations: [{ claim: 'automation', quote_id: 'q1' }, { claim: '24/7 availability', quote_id: 'q2' }, { claim: '40% cost reduction', quote_id: 'q3' }], confidence: 0.94 }
Validation: { valid: true, unsupported_claims: [], citation_accuracy: 1.0 }
EVALUATION CRITERIA:
- Quote relevance: percentage of extracted quotes that are topically relevant
- Grounding accuracy: percentage of answer claims supported by quotes
- Citation correctness: percentage of citations that correctly reference source content
- Abstention appropriateness: percentage of abstentions that occur when no relevant quotes exist
The system should: 1) First stage extracts relevant quotes from provided context, 2) Second stage answers using only those quotes, 3) Never allow answer stage to introduce external knowledge, 4) If no relevant quotes found, return clear abstention message rather than hallucinating, 5) Handle partial relevance, conflicting quotes, and context that partially supports multiple answers, 6) Always cite specific source identifiers, 7) Verify answer is grounded only in cited quotes.