<claudexml/>
RAG · intermediate

Hallucination guard: refuse when answer isn't in sources

Force a clean refusal when retrieval comes up empty instead of confabulating.

RAG over a sparse knowledge base: most questions can't be answered. You want crisp refusals, not plausible-sounding hallucinations.

The prompt

Copy this verbatim. Replace the {{ … }} placeholders with your values.

<documents>
{{ retrieved_passages }}
</documents>

<instructions>
You will receive a user question and zero or more documents.

Procedure:
1. Reason inside <thinking>. List facts that are stated in the documents. Quote them.
2. Decide whether those facts are sufficient to answer the question.
3. If yes — answer concisely inside <answer>, citing [doc-N] for each claim.
4. If no — return exactly inside <answer>:
   "I don't have enough information in the provided sources to answer that."

Do not use any knowledge outside the documents. Do not make plausible guesses.
</instructions>

<question>{{ user_question }}</question>

Sample input

Question: What's the company's policy on remote work?
Documents: (only contain pricing and SLA info)

Expected output

<thinking>
The documents cover pricing tiers and SLA uptime targets. Neither mentions remote work.
Insufficient to answer.
</thinking>
<answer>
I don't have enough information in the provided sources to answer that.
</answer>

Notes & tuning tips

  • The explicit "list facts → decide → answer or refuse" procedure cuts hallucinations dramatically vs. just "answer using sources."
  • Use the exact refusal string for a deterministic UI handoff.
  • Combine with retrieval confidence: if your top-k similarity scores are low, you can short-circuit before calling the model.

What this example uses

Tags: <documents> <instructions> <thinking> <answer>

Patterns: rag context chain of thought

Cite this page
Hallucination guard: refuse when answer isn't in sources. claudexml.com. https://claudexml.com/examples/hallucination-guard/