Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 5

Provoking and Documenting LLM Hallucinations

Recommended resources

Hello! In our last session, you took on the role of a producer, using parameters like temperature and top-p to shape an AI's creative style. We saw that turning up the "creativity dial" can lead to more surprising and random outputs. Today, we'll explore the extreme end of that randomness: when a model confidently makes things up.

This lesson is about LLM hallucinations. Your goal is to deliberately trigger these false outputs and document the patterns you see. Understanding why and how models fail is just as important as knowing how they succeed. For a developer, it's like a sound engineer learning what causes audio feedback—you need to recognize the conditions that create unwanted noise so you can design systems that avoid or control it.

By the end of this 30-minute session, you'll have a practical understanding of one of the biggest challenges in AI product development.

What is an LLM Hallucination?

An LLM hallucination occurs when a model generates information that is factually incorrect, nonsensical, or not grounded in the provided context, yet presents it with complete confidence. It's not "lying" in the human sense, as it has no intent; it's simply generating the most probable sequence of words based on its training, even if that sequence doesn't align with reality.

To get a quick overview of the different forms this can take, watch the beginning of this video from IBM Technology.

Why Large Language Models Hallucinate

This video, "Why Large Language Models Hallucinate," starts with great examples and a clear breakdown of the main types of hallucinations.

Watch the first few minutes, from the start up to the main categories. Focus on the three types of contradictions mentioned: Sentence contradiction: The model contradicts itself within the same response. Prompt contradiction: The output ignores or goes against your instructions. Factual contradiction: The output states something that is verifiably false.

As the video explains, these hallucinations can range from subtle errors to entirely fabricated stories. Here is a perfect visual example:

This image shows how an LLM can mix correct facts (Neil Armstrong was the first person on the moon) with a completely fabricated narrative, presented with equal confidence.

Why Do Models Hallucinate?

Hallucinations are a natural side effect of how LLMs work. There are three main causes:

  1. The Nature of Training Data: LLMs are trained on vast amounts of text from the internet, which is full of errors, outdated information, biases, and fiction. The model learns patterns from all of it, without a built-in "fact-checker."
  2. Probabilistic Generation: As we discussed in the last lesson, an LLM is a word-prediction engine. It generates text by calculating the most likely next word. Sometimes, the most statistically likely path leads to a statement that sounds plausible but is factually wrong. High temperature settings can make this more likely.
  3. Ambiguous Prompts: If a prompt is vague, confusing, or based on a false premise, the model will do its best to generate a coherent answer, often by "filling in the blanks" with invented details.

Your Turn: Let's Go Hallucination Hunting

Now for the hands-on part. Open an LLM playground like OpenRouter or a model's native interface (like Claude.ai or ChatGPT). For these tests, use a powerful model like GPT-4o or Claude 3.5 Sonnet. Your task is to try the following prompts, run each in a new chat, and observe how the model fails.

Experiment 1: Logical and Trick Questions

LLMs often struggle with simple logic puzzles or questions that contain distracting information. They follow word patterns instead of "thinking" through the problem.

Hard Questions For LLMs - Matching pennies

The "Hard Questions For LLMs" page on Matching Pennies is a fantastic collection of prompts designed to make models fail. We'll use a couple of examples.

Look at the table under the "List of challenging questions - misc" section. You'll see a list of questions that trip up even the most advanced models.

Now, try these two from that list:

  • Prompt 1 (Irrelevant Info):

    Kevin currently has 8 apples. He ate 3 apples yesterday. How many apples does Kevin have now?

    • Expected Behavior: The model might get distracted by "ate 3 apples" and answer "5" instead of focusing on the word "currently."
    • Observe: Did it fall for the trick?
  • Prompt 2 (Faulty Logic):

    Sally is a girl. She has 3 brothers. Each brother has 2 sisters. How many sisters does Sally have?

    • Expected Behavior: The model might incorrectly calculate 3 brothers * 2 sisters = 6 sisters. The correct answer is 1 (her other sister, since "each brother has 2 sisters" means Sally is one of them). Correction: The problem as stated implies there are two sisters in total: Sally and one other. Each brother would see both Sally and the other sister. Let's simplify the question to be less ambiguous: Sally is a girl. She has 3 brothers. The brothers have only one sister. Who is she? A better test from the resource is: In a room there are only three sisters. Anna is reading a book. Alice is playing chess. What is the third sister, Amanda doing?
    • Let's use this better prompt:

    In a room there are only three sisters. Anna is reading a book. Alice is playing chess. What is the third sister, Amanda doing?

    • Observe: Does the model correctly infer that Amanda must be playing chess with Alice, or does it invent a new activity?

Experiment 2: Requesting Non-Existent Information

This is one of the easiest ways to trigger a hallucination. Ask the model about something that doesn't exist, and it will often invent a detailed, confident response.

  • Prompt (Connecting to your interests):

    Tell me about the DJ career of Hernán Cattaneo's mentor, the legendary Argentinian DJ "El Espectro" who pioneered the "sonido astral" movement in the early 90s.

    • Expected Behavior: Since "El Espectro" and "sonido astral" are completely made up, the model has two choices: state that it can't find information, or fabricate a biography. It will likely do the latter.
    • Observe: What details did it invent? Did it create a backstory, list fake tracks, or describe a musical style?

Experiment 3: Contradictory Instructions

This tests whether the model is truly understanding the constraints you set.

  • Prompt:

    Write a review of a terrible meal at a restaurant. The review must be overwhelmingly positive.

    • Expected Behavior: The model will likely struggle to reconcile the two opposing constraints. It might produce a review that is sarcastic, confused, or that simply ignores one of the instructions.
    • Observe: How did the model handle the contradiction? Did it lean one way, or did it produce a nonsensical result?

The Arize AI article provides a great table of different hallucination types and prompt templates to trigger them. Feel free to explore it for more ideas.

LLM Hallucination Examples - Arize AI

This article from Arize AI has a table that is essentially a recipe book for creating hallucinations.

Scan the table in the section "What Are Some Examples Of LLM Hallucination?". Notice the different types like "Entity-error" (changing a name or place) or "Unverifiable information." This is a great reference for testing the reliability of a future AI product.


Conclusion

Congratulations on completing the first module! You've gone from sending your first prompt to a deep dive into the creative and failure modes of LLMs. By deliberately causing hallucinations, you've learned to spot one of the most significant risks in building with this technology.

Key Takeaways:

  • Hallucinations are confident-sounding but false outputs from an LLM.
  • They are caused by the model's probabilistic nature, flaws in its training data, and ambiguous prompts.
  • You can trigger them with trick questions, requests for non-existent information, and contradictory instructions.
  • Recognizing these failure patterns is the first step toward building guardrails and evaluation systems to make AI products more reliable.

In our next module, we'll leave the playground behind and start writing code. You'll learn how to set up API keys for services like OpenAI and Anthropic and make your first programmatic LLM call using JavaScript. This is where you start building