Skip to content

Understanding AI

AI hallucinations: why AI makes things up and how to catch it

AI tools sometimes invent facts, sources and code that sound real. Why these "hallucinations" happen, how to spot them, and habits that keep children safe.

By the GenKid team · · Updated · Facts checked · 5 min read

Key takeaways

  • AI hallucinations are confident-sounding answers that are false — invented facts, quotes, sources or code — and they happen because language models generate likely-sounding text rather than checking whether it's true.
  • In code, AI can invent functions or even software packages that don't exist, which attackers can exploit.
  • Warning signs include very specific details with no source, sources you can't find, and answers that change when you ask again.
  • The fix is a habit: check important answers against reliable sources, and test any code before trusting it.
  • Developers can reduce hallucinations but haven't eliminated them, so checking stays essential.

What are AI hallucinations?

An AI hallucination is when an AI tool produces something false but presents it as true. It's not a glitch or a lie: the tool is predicting likely-sounding text, and sometimes likely-sounding text is wrong.

People use the word hallucination for when an AI produces something false but presents it as true — a made-up fact, a book that doesn't exist, a quote nobody said, or code that calls a function that isn't real. The US National Institute of Standards and Technology uses a more careful term, confabulation: when generative AI systems "generate and confidently present erroneous or false content". NIST also notes the concern that words like "hallucination" make AI sound human.

That's the problem with both words: they suggest the AI is imagining things like a person would. It isn't. It's doing exactly what it was built to do — predicting likely text — and sometimes likely text is wrong.

Why it happens

AI chatbots and coding tools are built on large language models. These models are trained to continue text in a way that sounds right, based on patterns in huge amounts of writing. They don't have a built-in fact-checker.

So when you ask about something rare, very recent or ambiguous, the model still produces a fluent answer — because producing fluent text is what it does. If the pattern "a study by [name] in [year] found..." is common in its training data, it can generate a convincing-looking study that never happened.

Other causes include:

  • Out-of-date training data — the model may not know about recent events.
  • Leading questions — if you ask "why is X true?", the model may assume it is.
  • Pressure to answer — models are often trained to be helpful, so they may answer rather than say "I don't know".

Hallucinations in code

AI coding tools can make things up too:

  • Invented functions or settings that don't exist in the language or library.
  • Invented packages. A study of 576,000 AI-generated code samples, presented at USENIX Security 2025, found that 19.7% of the software packages the models suggested didn't exist: about 5% for commercial models and about 22% for open-source models. Attackers can register those made-up names and fill them with malicious code — a trick sometimes called "slopsquatting". See fake packages and AI.
  • Confident claims that code works when it doesn't.

That's why testing matters so much. Code either runs correctly or it doesn't, and tests give you an answer the AI can't talk its way around.

How to spot a likely hallucination

Be suspicious when you see:

  • Very specific details with no source — exact numbers, dates or quotes.
  • Sources you can't find — search for the title; if nothing comes up, it may be invented.
  • Answers that change when you ask the same question again.
  • Too-perfect answers to obscure questions.
  • Code that uses names you've never seen — check the official documentation.

Habits that keep you safe

  1. Check important facts with reliable sources: official sites, textbooks, trusted news.
  2. Ask for sources, then open them. Make sure they exist and say what the AI claims.
  3. Ask "how sure are you?" — and remember the answer isn't reliable either, but it can prompt a closer look.
  4. Test code before trusting it, and review every change.
  5. Never install a package just because an AI suggested it. Check it's real and widely used first.
  6. Use AI to understand, not to decide — especially for health, safety, money or schoolwork that will be marked (see hints, not answers).

Hallucinations aren't the only way AI output goes wrong. It can also be unfair or one-sided, which is a different problem with different causes; see AI bias explained. And AI-made images and videos can be deliberately misleading; see how to spot deepfakes.

Teaching children to question AI

Children are often more trusting of AI than adults realise. A 2025 Internet Matters survey found that 40% of children who use chatbots had no concerns about following their advice, and another 36% weren't sure. And in Ofcom's 2025 Children and Parents: Media Use and Attitudes report (2024 survey data), 72% of parents said they worried their child couldn't tell what's real from what's fake online.

A simple family rule helps: "AI can help you think, but it doesn't get the final word." Practise together by asking a chatbot questions where you already know the answer, and by checking its sources. For more ways to start these conversations, see how to talk to your child about AI.

GenKid's AI helper labels every reply as AI-generated, and lessons ask learners to check and explain what the AI produced rather than accept it. See our safety approach.

Frequently asked questions

Does asking for sources stop AI hallucinations?

It helps, but only if you open them. AI tools can invent sources that look real, or cite a real page that doesn't say what the tool claims. Tools connected to search are more likely to point to real pages, but you still need to check that the page supports the answer.

Can AI hallucinations be completely fixed?

Not yet. Developers can reduce them, for example by connecting models to trusted sources, but current AI tools can still produce confident mistakes. Checking remains essential.

How do I know if an AI answer is true?

Check it against reliable sources you can open yourself. Be especially careful with specific numbers, quotes, recent events and anything important.

Why does AI sound so sure when it's wrong?

It generates fluent text in a confident style because that's common in its training data. Its tone doesn't tell you how accurate it is.

Sources

  1. Artificial Intelligence Risk Management Framework: Generative Artificial Intelligence Profile (NIST AI 600-1) (opens in a new tab) — National Institute of Standards and Technology, 2024
  2. We have a package for you! A comprehensive analysis of package hallucinations by code generating LLMs (opens in a new tab) — Spracklen et al., USENIX Security 2025
  3. Me, myself and AI: understanding and safeguarding children's use of AI chatbots (opens in a new tab) — Internet Matters, 2025
  4. Children and Parents: Media Use and Attitudes Report 2025 (opens in a new tab) — Ofcom

How we write: GenKid articles are researched and drafted with the help of AI tools, then checked in a separate review step against the sources listed above before they are published, and re-checked when they are updated. Rules and products change, so check official pages for your country before acting on anything here. This article is general information, not legal advice. Spotted a mistake? Email hello@genkid.app.

Safety & privacy

What is slopsquatting? Fake AI packages explained

Slopsquatting is when attackers publish malicious packages under names AI coding tools invent. Learn why it happens and six checks before installing a package.

4 min read

Building with AI

How to prove your app works: testing for beginners

What software testing is, how to test an app by hand, how to write your first automatic checks in JavaScript, and why tests matter more when AI writes code.

4 min read