liveBook · Manning

Hallucination

As explained in Build Python Web Apps with Streamlit

An AI hallucination is a generated response that presents invented or unsupported information as if it were factual.

An AI hallucination is a plausible-sounding response that presents incorrect or completely invented information as factual. It happens because a large language model generates text from statistical patterns rather than from an understanding of facts. section 9.6.1

When building an AI-powered application, keep these practical points in mind:

  • A model can confidently produce misleading questions or answers, even when the wording sounds convincing. section 9.6.1
  • Probabilistic token generation can make outputs vary, but changing response variability does not guarantee factual accuracy. section 9.6.1
  • Connecting the model to external information can reduce hallucinations, although no strategy guarantees that they will disappear. section 9.6.1 section 10.5

An invented product answer

A customer asks Nibby which fountain pens a stationery store carries. The bot names fictional brands such as InkStream and RoyalQuill, despite receiving no information about those products. The confident answer is a hallucination, not evidence that the products exist. section 10.5

Figure 10.14 Nibby makes up information when it doesn’t know the answer.

Use the example conversation to inspect how an AI assistant fills an information gap with invented product details. section 10.5

How Build Python Web Apps with Streamlit covers it

How deep it goes
Defines the failure and its probabilistic cause, then defers detailed hallucination handling to external knowledge sources.
Examples
Uses repeated trivia questions and Nibby’s fictional fountain-pen brands to demonstrate unreliable generation.
What you can do after
Evaluate generated claims as potentially unsupported and recognize external information as a mitigation strategy.
How it connects
Connects hallucinations to large language models, token probabilities, external sources, and retrieval-augmented generation.

Also explained in

Compare how 29 books explain hallucination →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Python Web Apps with Streamlit. The section links point to the parts of the book it draws on.