RAG · intermediate
RAG over docs with [doc-N] citations
Answer a question from retrieved passages and cite every claim by source ID.
Customer support copilot: answer using only your knowledge base, refuse cleanly when the answer isn't there, and cite sources the human can verify.
The prompt
Copy this verbatim. Replace the {{ … }} placeholders with your values.
<documents>
<document>
<source>doc-1: pricing.md</source>
<document_content>{{ passage_1 }}</document_content>
</document>
<document>
<source>doc-2: refund-policy.md</source>
<document_content>{{ passage_2 }}</document_content>
</document>
</documents>
<instructions>
Answer the user's question using only the documents above.
Cite every claim with [doc-N] inline.
If the answer is not in the documents, reply exactly:
"I don't have that information in the provided sources."
Do not draw on outside knowledge.
</instructions>
<question>{{ user_question }}</question>
Sample input
Question: How much does the Pro plan cost and can I get a refund?
Passage 1: The Pro plan is $20/month and includes 100 GB of storage.
Passage 2: All paid plans include a 14-day money-back guarantee.
Expected output
The Pro plan is $20 per month [doc-1]. You can request a refund within 14 days of purchase [doc-2].
Notes & tuning tips
- Documents-first ordering matters once context gets long — Anthropic's guidance is reference material before instructions.
- The exact refusal string lets you regex for it and offer a human handoff button.
- Validate cited doc IDs against your retrieval set in code; the model occasionally cites adjacent docs.
What this example uses
Tags: <documents> <document> <source> <instructions>
Patterns: rag context
More like this
rag
Multi-document compare-and-contrast
Synthesize three vendor quotes into a table plus a one-paragraph recommendation.
ragHallucination guard: refuse when answer isn't in sources
Force a clean refusal when retrieval comes up empty instead of confabulating.
Cite this page
RAG over docs with [doc-N] citations. claudexml.com. https://claudexml.com/examples/rag-with-citations/