Hallucinations
Hallucination is when an LLM generates confident-sounding text that is factually incorrect. It is one of the most important limitations to understand and mitigate.
What Hallucination Is
Hallucination is when an LLM generates text that sounds plausible and confident but is factually wrong.
Examples of hallucinations:
- A model invents a research paper with a plausible title, journal, and author list that does not exist
- A model states a specific statistic (e.g., '73% of companies use AI') with no real source
- A model gives wrong information about a real person, misattributes quotes, or invents biographical details
- A model gives incorrect code that looks right but has subtle bugs
Hallucination happens because the model generates statistically likely sequences, not verified facts.
Deep Learning ⊂ Machine Learning ⊂ Artificial Intelligence
Why LLMs Hallucinate
- The model was trained to produce likely text, not verified facts
- The model has no internal fact-checking mechanism
- When the model is uncertain, it generates the most statistically plausible continuation
- Confident-sounding language is common in training data, so the model generates it
- Some information was incorrectly represented in training data
How to Reduce Hallucination Risk
# Strategies to reduce the impact of LLM hallucinations
strategies = {
"Use RAG (Retrieval-Augmented Generation)": {
"what_it_does": "Provide the model with relevant verified documents as context before asking your question",
"example": "Instead of asking 'What does our refund policy say?', give the model the policy document and ask it to extract the answer",
},
"Ask for sources": {
"what_it_does": "Ask the model to cite its sources. It may still hallucinate sources, but it is easier to verify",
"example": "Always ask: 'List the specific sources or evidence for each claim you make'",
},
"Verify independently": {
"what_it_does": "Treat LLM output as a draft to verify, not a final answer",
"example": "Use the LLM to draft a summary, then verify every specific claim against original sources",
},
"Use lower temperature": {
"what_it_does": "Lower temperature reduces creativity and makes the model stick to more likely outputs",
"example": "For factual tasks, use temperature=0 or 0.1",
},
"Acknowledge uncertainty": {
"what_it_does": "Ask the model to say when it is not sure",
"example": "Add to your prompt: 'If you are not confident about a fact, say that you are uncertain rather than guessing'",
},
}
print("Reducing LLM Hallucination Risk:")
print()
for strategy, details in strategies.items():
print(f"Strategy: {strategy}")
print(f" What it does: {details['what_it_does']}")
print(f" Example: {details['example']}")
print()Key Takeaways
- Hallucination is when an LLM generates confident-sounding text that is factually incorrect.
- The model was trained to produce likely text, not verified facts
- The model has no internal fact-checking mechanism
- When the model is uncertain, it generates the most statistically plausible continuation