Overview

5 Detecting and quantifying hallucinations

This chapter explains that hallucination detection is fundamentally a factuality problem: fluent, confident text can still be unsupported, partially fabricated, or completely invented. Because standard metrics like BLEU, ROUGE, or even semantic similarity and generic judge models do not directly measure whether claims are grounded in evidence, the chapter frames hallucinations through a reliability lens. It separates output quality into two dimensions—contextual grounding and factual alignment—so that systems can distinguish faithful answers, intrinsic errors that misstate provided sources, extrinsic errors that add unsupported details, and mixed cases that look plausible but are still wrong.

The chapter’s centerpiece is SelfCheckGPT, a zero-resource method for open-domain detection that treats consistency across multiple stochastic generations as evidence of factuality. If a model truly knows a fact, it should reproduce it reliably; if it is fabricating, details tend to vary across samples. SelfCheckGPT operationalizes this by generating reference samples and comparing them to the target response using several variants, including BERTScore, NLI, question-answering, and LLM-as-a-Judge. The chapter also notes the method’s strengths and limitations: it works without external knowledge bases or model internals, but it can miss stable false beliefs, incurs extra compute, and is sensitive to sampling choices like temperature and number of samples.

For production use, the chapter recommends a layered pipeline: decompose responses into atomic claims, route source-backed claims to reference-based verification, use consistency-based methods for open-domain claims, and aggregate results into faithfulness scores and operational actions such as logging, review, or blocking. It emphasizes that verification is expensive compared with generation, so online systems often rely on lightweight signals such as token probabilities or small NLI models, while deeper checks are better suited to offline audits and regression testing. The broader takeaway is that hallucination detection should be integrated into evaluation and alignment loops, with thresholds calibrated to the application’s risk profile, and with the expectation that some hallucination will persist despite mitigation efforts.

A flow chart for choosing a hallucination detection strategy. Closed-domain tasks can use grounding based on sources to verify claims. Open-domain tasks require self-consistency checks, or rely on external fact retrieval, or other factual alignment signals.
A production hallucination detection pipeline. Generated responses are decomposed into claims, routed to the appropriate verifier, aggregated into response-level metrics, and converted into actions such as logging, review, regeneration, or blocking.
The LLM Reliability Quadrant. Contextual grounding (vertical axis) asks whether the output stays within the provided sources. Factual alignment (horizontal axis) asks if the output is correct according to verifiable evidence. The safest output is both grounded and aligned. The riskiest output is neither grounded nor aligned. The mixed-signal quadrants are operationally important because the output can look based on source but wrong, or look correct but not grounded.
An example of an agent assistant outputs answers in a very fluent and convincing manner, but the answer is incorrect.
The SelfCheckGPT pipeline. The same prompt produces one target response and N stochastic examples. Each sentence in the target is checked for consistency against the samples. Consistent sentences score as factual; inconsistent sentences score as hallucinated.

Summary

  • Closed-domain tasks are constrained to a provided context (the 'source of truth') that the output must strictly adhere to. Open-domain tasks lack this explicit boundary, requiring the model to rely on its internal parametric knowledge or retrieve information from external sources like web search or a knowledge base.
  • The LLM Reliability Quadrant classifies model outputs along two dimensions: contextual grounding (whether the output stays within the source) and factual alignment (whether it is correct). Intrinsic hallucinations are grounded but misaligned; extrinsic hallucinations are ungrounded and misaligned. The "extrinsic but correct" quadrant is deceptively dangerous because it signals unreliable generation even when the output happens to be right.
  • SelfCheckGPT exploits the consistency principle: factual statements remain stable across multiple independent generations while hallucinations vary. This enables zero-resource detection without access to knowledge bases, model internals, or ground truth.
  • SelfCheckGPT offers four variants with different trade-offs: BERTScore for fast, low-cost screening; NLI for detecting factual contradictions; QA-based for fine-grained claim verification; and LLM-as-a-Judge for the highest accuracy.
  • SelfCheckGPT cannot detect consistent hallucinations where the model has stably learned incorrect information from training data. Complement consistency-based detection with reference-based verification whenever grounding sources are available.
  • Claim decomposition and verification provide a structured alternative that breaks text into atomic factual claims and verifies each independently, producing granular, actionable faithfulness scores.
  • Online hallucination detection prioritizes latency, using lightweight signals like token probabilities and fast NLI models. Offline detection prioritizes accuracy, using full SelfCheckGPT or comprehensive claim decomposition for testing and auditing.
  • Hallucination detection integrates with the multi-dimensional evaluation framework from chapter 4 as a binary quality gate: responses that fail the faithfulness check should not proceed to graded evaluation of other dimensions.
  • Detection is necessary but not sufficient. The mitigation hierarchy progresses from prompt engineering through retrieval augmentation, fine-tuning, and RLHF, with each level building on detection as the monitoring layer.
  • Hallucination cannot be fully eliminated with current language model architectures. Design systems that assume some persistent hallucination rate and build human-in-the-loop safeguards for high-stakes decisions.

FAQ

What is hallucination in the context of LLM evaluation?Hallucination is when a model produces fluent, confident text that is fabricated or unsupported by verifiable evidence. In this chapter, “correct” or “aligned” means the claim is supported by evidence, not merely that it sounds plausible.
Why are BLEU, ROUGE, and BERTScore not enough to detect hallucinations?BLEU and ROUGE focus on lexical overlap with references, and BERTScore measures semantic similarity. Hallucinated content can still be fluent and semantically coherent, so these metrics do not directly detect factual errors or unsupported claims.
What is the difference between closed-domain and open-domain hallucination detection?Closed-domain tasks have a source document or database that defines what is true, so claims can be checked against that source. Open-domain tasks lack a grounding document, so detection must rely on factual alignment signals such as external retrieval, self-consistency, or uncertainty signals.
What are the two key dimensions in the LLM reliability quadrant?The two dimensions are contextual grounding and factual alignment. Grounding asks whether the output stays within the provided source material, while factual alignment asks whether the output matches verifiable evidence.
What are the four quadrants in the reliability framework?The four quadrants are: faithful, intrinsic hallucination, extrinsic but correct, and extrinsic hallucination. Faithful means grounded and aligned; intrinsic hallucination means grounded but misaligned; extrinsic but correct means ungrounded but factually correct; and extrinsic hallucination means both ungrounded and misaligned.
How does SelfCheckGPT detect hallucinations without external knowledge bases?SelfCheckGPT samples multiple independent generations from the same prompt and checks how consistent they are. Facts the model truly “knows” tend to appear consistently, while hallucinated details often vary across samples.
What are the main variants of SelfCheckGPT consistency checking?The chapter describes four variants: BERTScore-based consistency, NLI-based consistency, QA-based consistency, and LLM-as-a-Judge consistency. They differ in accuracy, cost, latency, and implementation complexity.
Why does NLI work better than BERTScore for factual hallucination detection?NLI can detect entailment and contradiction, so it can identify factual conflicts directly. BERTScore only measures semantic similarity, which may miss cases where two sentences are similar in wording but differ in an important fact like a number or date.
Why should hallucination detection pipelines decompose responses into atomic claims?Claim decomposition makes verification more precise and auditable. Instead of judging an entire response at once, the system can verify each factual claim separately, identify which claims are unsupported, and compute a more meaningful faithfulness score.
How should hallucination detection be integrated into production systems?A production pipeline should preprocess responses into claims or sentences, run appropriate detectors, aggregate the results into response-level metrics, and then take actions such as logging, review, regeneration, or blocking. Online systems usually use lightweight signals, while offline systems can afford more expensive methods like full SelfCheckGPT or detailed claim verification.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • LLM Evaluation and Alignment, The Foundational Ideas ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • LLM Evaluation and Alignment, The Foundational Ideas ebook for free