# Avoiding hallucinations

Web page: https://academy.memberpress.ai/courses/prompt-engineering-101/l12/

Lesson 12 of 19 in [Prompt Engineering 101](https://academy.memberpress.ai/courses/prompt-engineering-101/), 8 min.

Video: https://www.youtube.com/watch?v=Jz8Tt4Rq7GI

A hallucination is a confident, fluent, wrong answer. Claude does not know it is wrong. The answer is generated using the same mechanism as a correct answer — the model produces the most plausible-sounding next token given what it has already generated. If the training data does not contain the right answer, the model can still produce a plausible-sounding one.

You cannot prevent hallucinations entirely. You can prevent them from causing damage in the outputs you rely on.

**Why hallucinations happen**

Claude's training data contains a vast amount of text. For common topics — major historical events, well-documented scientific facts, widely published technical information — Claude's knowledge is reliable. For niche topics, recent events, private data, and anything that changes frequently (prices, regulations, personnel), Claude's knowledge is unreliable.

The pattern that creates the most damage: Claude knows something adjacent to what you asked, the adjacent knowledge is plausible in the context of your question, and Claude produces the adjacent knowledge as if it were the answer to your actual question. The answer sounds right because it is coherent and relevant. It is wrong because it is not about your specific situation.

**Technique 1: Ground in context**

Provide the source material in the prompt and instruct Claude to answer only from that material.

```
Answer the following question using only the text below.
If the answer is not in the text, say "I don't have that information in the provided text."

<text>
Acme Inc. was founded in 2010. The company has 47 full-time employees and operates in three markets: healthcare, finance, and logistics. Its headquarters are in Austin, Texas.
</text>

Question: What year was Acme Inc. founded, and what markets does it serve?
```

The instruction "using only the text below" is explicit. The fallback instruction "say 'I don't have that information'" gives Claude a path when the text does not contain the answer. Without the fallback, Claude may fill the gap with a plausible-sounding answer from its training data.

**Technique 2: Ask for citations**

When Claude answers from a provided text, ask it to cite the specific sentence that supports each claim.

"Cite the exact sentence from the provided text that supports each claim in your answer."

If Claude cannot cite a sentence, the claim is not in the text. This forces Claude to stay grounded and gives you a way to verify.

**Technique 3: Encourage uncertainty**

Add an explicit permission to say "I don't know":

"If you are uncertain about any part of the answer, say so explicitly. Do not guess."

Claude's default behavior leans toward confident answers. This instruction opens space for uncertainty.

**Red flag patterns**

When Claude says "As of my knowledge cutoff..." or "Based on my training data...", it is signaling that it is drawing on training knowledge rather than provided context. In a grounded prompt, this means Claude has left the text you provided. Ask it to answer only from the text you provided.

**If you get stuck**

If Claude is still producing information that is not in your source text, the source text may be too long for Claude to process accurately in a single prompt. Break it into sections and ask about each section separately.

If the citation technique produces citations that do not match what Claude said, the mismatch is the hallucination — Claude generated an answer, then found a plausible-sounding citation for it. Both the answer and the citation should be checked against the source.

**Cross-reference**

L19 (Search and retrieval) covers RAG — a system-level technique for automatically injecting relevant source documents into the prompt at query time, which extends grounding beyond what fits in a single prompt.

**Deliverable**

Take a question about a topic where Claude might hallucinate — a specific company, a recent event, a piece of internal data. Write a grounded prompt that provides the source text and instructs Claude to answer only from it, with a fallback for missing information. Verify that the answer is accurate against the source.

**Further reading**

- ["The Persona Will Lie to You in a Beautiful Voice"](https://sethshoultes.com/blog/personas-claim-facts-confidently.html) — the failure mode where a confident voice masks invented facts, and what guardrails actually catch it.
- ["Plausible Code That Doesn't Compile"](https://sethshoultes.com/blog/agents-hallucinate-apis.html) — the same pattern for code: hallucinated APIs that look right and fail at runtime.

## Try these prompts

- Answer using only the following text. If the answer isn't in the text, say "I don't have that information." Text: "Acme Inc. was founded in 2010 and has 47 employees."
- Cite the specific sentence that supports your answer. What year was Acme founded?

Next: [Building complex prompts from scratch](https://academy.memberpress.ai/courses/prompt-engineering-101/l13/)
