
Module 7 Lesson 4: Reducing Hallucinations
How can we make AI reliable enough for a bank or a hospital? In our final lesson of Module 7, we explore the industry best practices for silencing the 'LIAR' in the machine.
Module 7 Lesson 4: Reducing Hallucinations
Hallucinations are the biggest barrier to AI adoption in serious industries like medicine, law, and finance. However, by using a multi-layered approach, we can reduce the hallucination rate from "Unreliable" to "Expert-level."
In this lesson, we look at the four pillars of building a reliable AI system.
1. RAG: The Ultimate Grounding Tool
The single most effective way to stop an AI from making things up is to give it the answer in the prompt. This is Retrieval-Augmented Generation (RAG).
- Without RAG: "Tell me my account balance." (AI guesses $500).
- With RAG: "Here is the bank database: [Account 123: $1,245]. Now, tell the user their account balance." (AI reads the number).
By turning the model's task from "Memorization" to "Summarization," we eliminate the need for the model to "guess" based on its training weights.
2. Few-Shot Prompting (Leading by Example)
Models often hallucinate when they aren't sure of the "format" or "tone" you want. By providing 3-5 examples of correct answers, you provide a "pattern" for the model to follow.
- Example: If you want the AI to extract dates from text, don't just ask for dates. Show it three examples of raw text and the correct dates you found. The model will "Attend" to your examples and copy your logic, rather than inventing its own.
3. Strict System Instructions (Giving an Out)
Remember the "Yes-Man" problem? We fix this by giving the model a "Permission to stay silent."
The Golden System Prompt:
"You are an assistant. Answer only using the provided context. If the answer is not in the context, say 'I do not have enough information to answer this.' DO NOT make anything up."
By explicitly rewarding the model for saying "I don't know," you combat the bias toward constant helpfulness that was baked in during training.
4. Temperature Control
If your task is factual, Turn down the heat.
- Set your Temperature to 0.0. This forces the model to always pick the most mathematically likely word. While this makes the model less "creative," it drastically reduces the chance of it taking a "random walk" into a hallucination.
graph LR
User["User Goal"] --> Pillar1["RAG (External Data)"]
User --> Pillar2["Few-Shot (Examples)"]
User --> Pillar3["System Prompt (Grounding)"]
User --> Pillar4["Temp 0.0 (Zero Creativity)"]
Pillar1 & Pillar2 & Pillar3 & Pillar4 --> Result["High-Reliability Output"]
5. Human-in-the-Loop
For high-stakes decisions, the final step is always a human. The AI generates a draft, but a human expert verifies the facts. This is why many AI-powered law firms use the AI to find the cases, but the lawyer reads the cases to ensure they weren't halluncinated.
Lesson Exercise
Goal: Build a "Safety" Prompt.
- Write a prompt that asks an AI about your favorite obscure hobby.
- Add a "Safety Instruction" telling it what to do if it doesn't know the answer.
- Test it. Does it honestly admit it's stumped? Or does it still try to "fake it"?
Observation: You'll find that even small changes in your instructions can significantly "quiet" the AI's imagination.
Conclusion of Module 7
You have now completed the most practical module for real-world builders:
- Lesson 1: What Hallucinations Are.
- Lesson 2: What causes them (Gaps, Blur, and Eagerness).
- Lesson 3: How to detect them (Logprobs and Consistency).
- Lesson 4: How to reduce them (RAG and Prompting).
Next Module: We look at the ethics and safety of AI. In Module 8: Bias, Safety, and Alignment, we'll learn about the "invisible filters" that prevent LLMs from being harmful.