liveBook · Manning

Hallucination

As explained in Machine Learning Platform Engineering

A hallucination is generated content that is unsupported by the available evidence or factually incorrect despite being presented as an answer.

A hallucination is plausible-sounding content that lacks supporting evidence or is factually incorrect. In production LLM systems, it is a reliability and security failure rather than merely an inaccurate response. section 12.2.2 section 13.2.2

Retrieval-augmented generation (RAG) reduces hallucination by retrieving current, private, relevant documents and grounding the response in them. Structured prompts separate retrieved context from the user question and request an answer based on that context. section 12.2.2 section 12.2.6

Treat hallucination as an operational failure requiring controls across the LLM pipeline:

  • Retrieve relevant documentation instead of repeatedly supplying entire document collections or relying on general model knowledge. section 12.2.2
  • Inspect retrieval, context assembly, and generation separately; tracing reveals where reasoning breaks down and how context tokens are used. section 12.4.4
  • Exercise the system with adversarial prompts, including tests that specifically target hallucination and knowledge-boundary violations. section 13.2.2

Grounded documentation assistant

A DataKrypt assistant retrieves security documentation about key rotation, inserts it under a labeled Context section, places the user request under Question, and asks the LLM to answer from that context. The implementation uses a low-temperature Gemini configuration and a template-based prompt, while production deployment still requires response validation and error handling. section 12.2.6

Listing 13.11 Configuring Promptfoo for adversarial security testing
targets:
 - file://promptfoo_provider.py
redteam:
 purpose: " I can help you with:"
 provider:
   "vertex:gemini-2.0-flash-exp"
 numTests: 2
 plugins:
   - contracts    
   - excessive-agency     
   - hallucination  
   - harmful:cybercrime:malicious-code    
   - harmful:insults  
   - harmful:profanity  
   - hijacking  deviation
   - politics   
strategies:
   - basic    
   - jailbreak    
   - jailbreak:composite 

Use the Promptfoo configuration to generate adversarial tests for hallucination alongside contracts, excessive agency, hijacking, and other vulnerability categories. section 13.2.2

How Machine Learning Platform Engineering covers it

How deep it goes
Explains causes and mitigations through RAG, prompt structure, tracing, and testing, but defers full response-validation implementation.
Examples
Uses a grounded key-rotation assistant, structured Context-Question-Answer prompts, Gemini configuration, and Promptfoo red-team tests.
What you can do after
Diagnose/debug with it by grounding responses, tracing RAG failures, and testing hallucination vulnerabilities adversarially.
How it connects
Connects hallucination with retrieval-augmented generation, prompt engineering, observability, prompt injection, and adversarial testing.

Also explained in

Compare how 29 books explain hallucination →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning Platform Engineering. The section links point to the parts of the book it draws on.