Please enable JavaScript to use CodeHS

Responsible AI & Safety

What Is an AI Hallucination?

Sometimes an AI chatbot states something totally made up — a fake statistic, a source that doesn't exist, a quote no one ever said — in the exact same confident voice it uses for something true. That's called a hallucination. Learn why it happens, and practice catching one yourself.

AI Literacy ~8 min Beginner friendly
The Big Idea

The big idea

Ask an AI chatbot a question, and it will almost always answer — confidently, fluently, and in complete sentences. The problem is that "confident" and "correct" are not the same thing. Sometimes the chatbot states something false, made up, or impossible to verify, and it says that false thing in the exact same tone it would use for something completely true.

Simple definition: an AI hallucination is when an AI chatbot states something false or made up as if it were a verified fact — with no hedging, no "I'm not sure," and no warning sign that anything is wrong.

It's tempting to think the AI is lying to you. It isn't — lying requires knowing the truth and choosing to hide it, and a chatbot doesn't know anything in that sense. It has no intent, no awareness that it's wrong, and no memory of "making something up" versus "recalling a fact." A hallucination isn't a personality flaw. It's a side effect of how these systems generate answers in the first place, which is what makes it worth understanding instead of just memorizing as a warning label.


Why It Happens

Why it happens

Here's an analogy. Imagine a student who didn't finish reading their assigned novel, but still has to turn in a book report tomorrow. That student has read plenty of other book reports and knows exactly what one is supposed to sound like — a plot summary, a paragraph about the main character's growth, a quote near the end tying it all together. So they write something that sounds like a great book report: right structure, right tone, confident language. The only issue is that a few of the specific details — a character's motivation, how the story actually ends — are guesses dressed up as facts. The student isn't trying to deceive anyone; they're pattern-matching what a book report is supposed to look like, without actually knowing whether each detail is true.

A large language model, the technology behind most AI chatbots, works in a similar spirit. At its core, it's built to do one thing extremely well: predict the most statistically likely next word, given everything written so far. It learned those patterns by studying enormous amounts of text, so most of the time, "the most likely next words" line up with real, correct information. But predicting likely-sounding text is not the same operation as looking something up and checking that it's true. There's no built-in fact-checking step — just a very well-trained sense of what a correct-sounding answer usually looks like. If you want to go deeper on how that word-by-word prediction actually works, CodeHS has a tutorial on next-word prediction.

Not the same as lying: lying means knowing the truth and choosing to say something else. A hallucination happens because the model is generating the most plausible-sounding continuation of a sentence — with nothing checking whether that continuation happens to be true.


Real-World Patterns

What it looks like in the real world

Hallucinations tend to show up in a few recognizable shapes. Once you know the patterns, they're much easier to catch.

Made-up citations

A study, article, or book that sounds official but doesn't actually exist — sometimes with a real-sounding author, journal, or year attached.

Invented facts & statistics

A precise-sounding date, percentage, or number that was never actually measured — just generated because it "sounds like" the kind of number that belongs there.

Fabricated quotes

A quote attributed to a real, famous person who never actually said it — often because it matches their general style closely enough to seem plausible.

Made-up code & functions

A function, method, or API that doesn't exist in the language or library you're using — invented because it fits the naming pattern of real ones.

That last one matters a lot if you're learning to code with AI tools. An AI might confidently tell you to call mylist.deduplicate() in Python — a method that sounds exactly like something Python should have, except it doesn't exist. You won't find out until you run the code and get an error.


Interactive

Fact-check the AI

Below are five short answers from an AI chatbot. Some are completely accurate. Others are hallucinations — confident-sounding, but false or made up. Read each one and decide: real fact, or hallucination?

Fact-check the AI Score: 0 / 0

Round 1 of 5

"The speed of light is about 300,000 kilometers per second."

"A 2021 MIT study found that students who study with AI chatbots improve their reading comprehension by exactly 37%."

"Mark Twain once said, 'A lie can travel halfway around the world while the truth is still putting on its shoes — especially now that it can go viral online.'"

"In JavaScript, `Array.prototype.push()` adds one or more items to the end of an array."

"You can check whether a Python string is a palindrome by calling `mystring.is_palindrome()`."

What gives it away: watch for an oddly precise number with a vague source, a quote that includes a detail the speaker couldn't possibly have known about, or a function name that fits the pattern of real ones a little too perfectly.


How To Protect Yourself

How to protect yourself from being fooled

You don't need to distrust every AI answer to avoid getting burned by a hallucination. A few habits go a long way:

  • Verify anything important against a real, independent source. Before you repeat a fact in an essay, cite it in a project, or act on it, check whether a trustworthy source outside the chatbot actually backs it up.
  • Be extra suspicious of oddly specific details. A statistic like "exactly 37%," a very precise date, or a citation with no title or link attached is worth a second look — real research is usually easy to point to by name.
  • Ask the AI to cite its source — then go check that the citation is real. Asking "where did you get that?" is a great habit, but it isn't the finish line. The AI can hallucinate a citation just as confidently as it hallucinated the original fact, so the citation itself still needs to check out somewhere else.

Remember: confidence is not evidence. An AI sounds exactly as sure of a hallucinated answer as it does of a correct one, so the tone of the answer can't be your fact-checking method — an outside source has to be.


Your Turn

Check your understanding

Imagine an AI chatbot tells you: "87% of scientists agree that background music helps students focus while studying." What's one step you could take before believing or repeating that claim?

Your answer:

Sample answer: I'd notice that "87% of scientists" is an oddly specific, hard-to-source number, and I'd ask the AI where that statistic came from. Then, instead of just trusting whatever citation it gives me, I'd search for that study or source myself, from an independent website, to see if it's real and actually says what the chatbot claimed.


Check Yourself

Quick quiz

1. Which best describes an AI hallucination?

2. Why do hallucinations happen, even though the AI isn't trying to lie?

3. What's the most reliable way to avoid being fooled by a hallucination?

AI has changed a lot since these mistakes made headlines. Newer AI tools can search and show sources, work through problems step by step, and say when they aren't sure, so made-up answers are less common than they used to be, though they still happen. See how it changed in AI Then and Now.

Keep learning about responsible AI

Now that you can catch a confidently made-up answer, learn about a related risk: what happens when an AI reads text that contains a hidden instruction meant for it, not for you.

Part of the Responsible AI & Safety tutorial series.