liveBook · Manning

Hallucination

As explained in LLMs in Production

A hallucination is generated content that is presented as plausible but is unsupported, inaccurate, or fabricated relative to the relevant facts or source material.

A hallucination is an LLM output that sounds right but is wrong or made up. In a production application, that is more than an odd answer: a plausible citation or link can mislead a user who has no reason to question it. Confident wording is not evidence of accuracy. section 3.2.7

Plausible books, nonexistent links

Asked for books from a particular publisher, an LLM supplied one nonexistent title and one real title from a different publisher. Both links looked like publisher URLs but led to 404 errors. The titles, authors, and URL shapes made the answers seem credible without making them correct. section 3.2.7

There is no established single cause or complete fix. Models can sound certain even when mistaken, and inconsistent answers are a substantial obstacle for applications that need reliable results. Treat factual claims as claims to check, especially when users will act on them. section 3.2.7 section 12.2.5

Ways to improve reliability include:

  • Provide relevant context through prompting; it can make responses more consistent, but does not make them inherently trustworthy. section 1.3
  • Evaluate prompt changes against answers you can check. A DSPy math example uses Chain of Thought and bootstrapped few-shot prompts without changing tokenization or fine-tuning the model. section 12.2.5
  • Check what leaves the application as well as what enters it: outputs can be outdated, factually incorrect, or contain copyrighted or licensed material. section 1.3
config = dict(max_bootstrapped_demos=2)     #1

class CoT(dspy.Module):
    def __init__(self):
    super().__init__()
    self.prog = dspy.ChainOfThought(QASignature, max_tokens=1000)

    def forward(self, question):
    return self.prog(question=question)

print("Creating Bootstrapped Few Shot Prompt")         #2
teleprompter = BootstrapFewShot(metric=gsm8k_metric, **config)
optimized_cot = teleprompter.compile(
    CoT(), trainset=gsm8k_trainset, valset=gsm8k_devset
)
optimized_cot.save("optimized_llama3_math_cot.json")

print("Evaluating Optimized CoT Prompt")            #3
evaluate(optimized_cot)                  
#149/200 74.5%

The listing shows how a bootstrapped few-shot Chain of Thought prompt is compiled and evaluated for math questions; it is an example of testing a mitigation, not a general cure for hallucinations. section 12.2.5

How LLMs in Production covers it

How deep it goes
Defines the failure through examples and tests prompt optimization, while leaving its causes unresolved and offering no complete fix.
Examples
Uses fabricated publisher links and a DSPy evaluation on grade-school math questions.
What it assumes
Assumes familiarity with LLM applications for the production discussion but defines hallucination through a plain-language example.
What you can do after
Evaluate/understand hallucination risks and test prompt-based improvements against checkable answers rather than trusting confident wording.
How it connects
Connects hallucination to prompt engineering, Chain of Thought, factual accuracy, and output security.

Also explained in

Compare how 29 books explain hallucination →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of LLMs in Production. The section links point to the parts of the book it draws on.