Skip to main content
In this lesson, we define hallucination in LLMs and explore practical techniques—such as prompt engineering and fine-tuning—to reduce or eliminate it.

What Is Hallucination?

Hallucination happens when a language model generates plausible-sounding but incorrect or ungrounded information. Instead of returning fact-based answers, the model “dreams up” details based on its training distribution rather than your prompt or real-world data.
The image features a robot with a thought bubble and text explaining "hallucination" in the context of language models, describing it as producing output not grounded in reality.

Example: When Hallucinations Occur

Consider this simple QA:
The image shows a conversation about the weight comparison between 1 kilogram of feathers and 2 kilograms of bricks, highlighting an incorrect response about their weights.
The correct answer is that two kilograms of bricks weigh more. Here, the model lacked context or misapplied its internal distribution, producing a convincing but wrong reply.

Strategies to Prevent Hallucination

Providing explicit context and instructions up front can dramatically reduce model errors and hallucinations.
Even the best prompts can’t replace real-world verification. Always cross-check critical facts.
The image is a diagram explaining how to avoid AI hallucinations by using prompt engineering, larger datasets, and fine-tuning. It shows the relationship between AI models and textual datasets.

Live Example: Adding Context

Without context the model may respond with an apology rather than an answer:
With context provided first, the model can answer accurately:

Live Example: Handling Recent Events

LLMs trained up to 2021 lack awareness of later events:
By injecting updated facts, the model can respond correctly:
The image shows a slide titled "Avoiding Hallucination" with a conversation about the winner of the original song at the 95th Academy Awards, highlighting the song "Naatu Naatu" from RRR as the winner.

Key Takeaway

Large language models may hallucinate when context is insufficient or outdated. By crafting precise prompts, supplying relevant data, and applying fine-tuning or retrieval augmentation, you’ll ensure your AI outputs are accurate, reliable, and grounded in real-world information.

Watch Video