LLM Hallucinations
Table of Contents + −
In the previous tutorial, we learned about temperature.
We saw that an LLM generates text by predicting tokens, and temperature can affect how those tokens are selected.
Now let’s understand one of the most important limitations of generative AI:
Hallucinations
🤖 What is an AI Hallucination?
An AI hallucination is when an AI model generates information that is incorrect, misleading, or not supported by the available information, while presenting it as if it were a valid answer.
For example, imagine you ask an AI:
“Who invented the telephone in 1850?”
The question itself contains a problem.
A model might still produce a confident-sounding answer instead of saying that the question needs correction.
That is the important point:
An LLM can generate a plausible answer even when the information is wrong or unavailable.
🤔 Why Does This Happen?
To understand hallucinations, remember what we learned about LLMs.
An LLM is fundamentally a model that learns patterns in data and generates tokens based on the input and context.
When you ask a question, the model doesn’t automatically perform a fact-check against reality.
A simplified view is:
The model’s job is to generate a useful continuation.
It is not automatically a truth-verification system.
💡 A Simple Example
Imagine you ask:
“Tell me about a book called ‘The Blue Moon of Delhi’ written by Arun Sharma.”
Suppose that book doesn’t actually exist.
An LLM might still generate something like:
“The Blue Moon of Delhi is a novel written by Arun Sharma…”
It may even invent:
- A publication year
- A story
- Characters
- Publisher information
- Reviews
The answer may sound convincing.
But that doesn’t mean it is true.
This is a hallucination.
🤔 Why Can the Answer Sound So Convincing?
This is what makes hallucinations dangerous.
LLMs are very good at producing natural-sounding language.
They can write:
Clear sentences +Good grammar +Confident tone +Detailed explanationBut:
Good writing does not guarantee factual correctness.
An answer can be beautifully written and completely wrong.
⚠️ Hallucination Does Not Mean the Model Is “Seeing Things”
The word hallucination can be confusing.
In AI, it doesn’t mean that the model is literally seeing or hearing something that isn’t there.
It is a term used to describe situations where a generative model produces unsupported or incorrect information.
So:
Hallucination ≠Human hallucinationIt is an AI-specific term describing incorrect generated content.
🤔 Why Can’t the Model Just Say “I Don’t Know”?
This is a very important question.
A language model is trained to generate useful responses.
If the information it needs isn’t available, the model may still try to produce a likely answer.
For example:
A well-designed system should ideally recognise uncertainty or lack of information, but this isn’t guaranteed.
⚠️ Hallucinations Can Be Small or Large
A hallucination doesn’t have to be an entirely imaginary answer.
It can be a small incorrect detail.
For example:
“The company was founded in 1998.”
when the correct year is 1999.
The rest of the answer may be correct.
So hallucinations can include:
- Completely fabricated information
- Incorrect facts
- Wrong dates
- Incorrect names
- Fake references
- Invented quotations
- Unsupported explanations
📌 Hallucinated References
One particularly important example is fabricated references.
An AI might provide:
“According to a 2024 research paper by…”
and then give a paper that doesn’t exist.
This is especially important when using AI for:
- Research
- Academic work
- Legal information
- Technical documentation
- Business decisions
A reference that looks real is not necessarily real.
⚠️ Can Hallucinations Happen With Code?
Yes.
An LLM can generate code that looks correct but doesn’t actually work.
For example, it may invent:
- A library that doesn’t exist
- A function that doesn’t exist
- An API endpoint that doesn’t exist
- An incorrect configuration option
The code may look perfectly reasonable.
This is why generated code should be tested rather than blindly trusted.
⚠️ Can Hallucinations Happen With Mathematics?
Yes.
An LLM can also make mathematical mistakes.
For example, it may confidently provide an incorrect calculation.
This happens because generating language and performing exact mathematical computation are different capabilities.
For calculations, it can be better to use a reliable calculation tool or program rather than relying only on generated text.
🌡️ Does Temperature Cause Hallucinations?
Temperature can influence generation behaviour, but it is not the fundamental cause of hallucinations.
We learned earlier:
Hallucination is a broader issue involving things such as:
- The model’s training
- The available context
- The quality of the prompt
- The model’s ability to reason
- Missing information
- Ambiguous questions
- Generation behaviour
So:
Lowering temperature does not magically eliminate hallucinations.
A model can produce a confident but incorrect answer even with a low temperature.
🤔 Why Does Confidence Matter?
One of the biggest problems is that an AI response may sound confident.
Consider:
“The company was founded in 1987 by John Smith.”
The sentence doesn’t tell you whether it is true.
The model’s confidence in wording is not the same as verified factual confidence.
This is a very important rule:
Never assume that a confident AI answer is automatically a correct answer.
⚙️ How Can We Reduce Hallucinations?
There is no single setting that completely solves hallucinations.
But we can reduce the risk.
1. Give Clear Instructions
A clear prompt can help the model understand what is expected.
For example:
“If the information is not available, say that you don’t know instead of making an assumption.”
This doesn’t guarantee perfect behaviour, but it can help.
2. Provide Reliable Context
If you already have trusted information, provide it to the model.
For example:
The model can then base its answer on the supplied information.
3. Use Retrieval
In applications where information changes or belongs to a private knowledge base, systems can retrieve relevant information before generating an answer.
Conceptually:
We’ll study the different retrieval-based approaches later in the course.
4. Verify Important Information
For important decisions, AI output should be checked against reliable sources.
This is especially important for:
- Medical information
- Legal information
- Financial information
- Security
- Production systems
- Academic research
AI can assist with these tasks, but generated information should not automatically be treated as verified truth.
⚠️ Hallucinations vs Errors
Are all AI mistakes hallucinations?
Not necessarily.
A model can make an ordinary reasoning or calculation mistake.
Hallucination generally refers to generated information that is unsupported or fabricated, especially when the model presents it as though it were valid.
The exact definition can vary across AI literature.
For this course, remember the practical meaning:
An AI hallucination is when the model generates information that isn’t supported by the facts or available information.
💡 A Simple Mental Model
Think of an LLM as a system that is very good at generating plausible language.
But:
Plausible ≠Always CorrectThat single idea is extremely important when working with generative AI.
🤔 Why Hallucinations Matter in AI Applications
When we build an AI application, we shouldn’t simply ask:
“Can the model generate an answer?”
We also need to ask:
“Where does the information in that answer come from?”
This leads to a broader AI engineering principle:
Generate +Verify +Ground with reliable informationWe’ll explore those ideas later when we start building real AI applications.
🧩 Key Takeaways
-
What is a hallucination?
When an AI model generates incorrect, fabricated, or unsupported information as though it were a valid answer.
-
Why does it happen?
Because an LLM is designed to generate responses based on learned patterns and available context; it is not automatically a fact-checking system.
-
Can hallucinations sound convincing?
Yes. That’s one of the biggest challenges.
-
Does low temperature eliminate hallucinations?
No.
-
How can we reduce hallucinations?
By using:
- Clear instructions
- Reliable context
- Retrieval when appropriate
- Verification
- Testing and evaluation
🧩 Where We Are
Our AI fundamentals path is now:
We now understand an important limitation of LLMs:
An LLM can produce an answer that sounds correct without the answer actually being correct.
That gives us a good foundation for the next part of our AI journey.