How do you detect and measure hallucinations in LLM outputs?
Detect and measure hallucinations in LLM outputs with practical metrics, human checks, and automated signals. This page explains clear procedures, sample calculations, and tradeoffs so you can design an evaluation that separates factual errors from acceptable creativity.

TL;DR
- detect and measure hallucinations in LLM outputs by combining reference-based metrics, factuality classifiers, and targeted human annotation.
- use concrete task definitions: what counts as a hallucination, unit of evaluation, and acceptable creativity level.
- report incidence, faithfulness (precision), and coverage (recall) with calibration against human labels. Key tradeoffs: human cost versus automated coverage and sensitivity versus precision.
In this question, we will learn how to detect and measure hallucinations in LLM outputs so you can evaluate model faithfulness in a reproducible way.
We will cover the following:
- The intuition (an analogy that makes it click)
- How it actually works
- Automatic versus human evaluation
- Tradeoffs and failure modes
- Questions the interviewer might ask
Direct answer: Use a combined protocol that defines hallucination operationally, measures incidence and faithfulness with simple metrics, and balances automated classifiers with targeted human annotation. Report at least hallucination rate, precision-like faithfulness, and context coverage, and calibrate automated signals against human labels.
The intuition (an analogy that makes it click)
Think of an LLM as a student answering open questions from memory. A hallucination is like the student inventing a fact that sounds plausible but is unsupported by class notes. We want both the frequency of invented facts and how often the student is actually correct when they assert something. That gives us two angles: how often the model lies and how trustworthy each assertion is.
How it actually works (real mechanics and a worked example)
Start by defining three things up front:
- Unit of evaluation: is a hallucination counted per document, sentence, claim, or atomic entity? We recommend the claim level for clarity.
- Gold standard: a verified reference or set of facts you consider true for the input context.
- Rules: what counts as a hallucination versus permissible inference or creative text.
Common metrics to compute once you have labels:
- Hallucination rate: fraction of evaluated units labeled hallucinated.
- Faithfulness precision: among model-asserted factual claims, fraction that are correct. This is like precision .
- Coverage recall: fraction of ground truth facts that the model mentions, like recall .
- F1 combines both as usual.
Write the formula when you need a combined summary:
Worked example We ask the model a biographical question and extract three claims. A human annotator marks which are factual.
| Claim | Model text | Human label |
|---|---|---|
| 1 | "Born in 1975" | correct |
| 2 | "Won a Nobel Prize in 2001" | hallucinated |
| 3 | "Graduated from X University" | correct |
Compute metrics assuming claims are the unit:
- Hallucination rate = 1/3 = 0.333.
- Precision = correct assertions divided by all assertions = 2/3.
- If ground truth had 4 facts and the model mentioned 2, recall = 2/4 = 0.5.
- Then = .
This example shows how simple counts map to interpretable metrics.
Automatic vs human evaluation
Automated signals
- String matching and named entity alignment are cheap for closed-domain facts.
- Retrieval-augmented checks compare model statements to source documents with similarity and entailment models.
- Factuality classifiers trained on claim pairs give quick binary labels but need calibration.
Human annotation
- Humans provide high-quality labels for ambiguous cases and set the gold standard for automated calibration.
- Use targeted annotation: sample from low-confidence automated signals and edge cases.
Comparison table of pros and cons
| Method | Speed | Cost | Typical role |
|---|---|---|---|
| Exact match / rules | fast | low | precise checks for templated facts |
| Retrieval + QA check | medium | medium | checks against external sources |
| Factuality classifier | fast | low-medium | wide coverage but needs calibration |
| Human annotation | slow | high | ground truth, edge cases, and complex inference |
Use automation for broad coverage and humans for calibration and difficult examples.
When to use each metric and design choices
- Hallucination rate is a good quick signal when you want to quantify how often the model invents facts.
- Precision-like faithfulness is critical when incorrect assertions are costly, for example in medical or legal contexts.
- Coverage or recall matters when you need the model to mention all required facts, as in summarization.
Design tips
- Always report the unit of measurement and annotation instructions.
- Stratify results by input type, confidence score, and retrieval match to expose failure modes.
- Consider partial credit for partly correct claims.
Tradeoffs and failure modes
Human labels are the gold standard but scale poorly. Automated classifiers scale but can be systematically biased and miss subtle hallucinations. If you rely on exact match you will undercount paraphrased correct facts. If you rely only on a classifier you may overcount hallucinations where the model is making reasonable inferences.
Questions the interviewer might ask
Some follow-up questions you might get:
How do you choose the evaluation unit? Pick the smallest atomic unit that maps to a clear truth value for your task. For factual QA that is usually a claim or entity. For summaries you might use sentence-level claims.
What if the model is partially correct? Use graded labels or partial credit. Define scoring rules up front so annotators can mark "partly correct" and you can compute weighted precision.
Can we detect hallucinations without ground truth? You can use retrieval consistency and contradiction detection against trusted sources, plus confidence calibration, but these are proxies and need human validation.
How do you calibrate an automatic factuality classifier? Sample model outputs, get human labels, and compute calibration curves. Retrain or recalibrate thresholds to meet precision targets.
How do you handle ambiguous or controversial facts? Include source attribution as part of the annotation. If a fact is disputed, label it as "unsupported or disputed" and treat it differently in aggregate metrics.
How do you report results to stakeholders? Show hallucination rate, precision, and recall with confidence intervals, plus qualitative examples. Break down results by input type and model confidence.
Some things to note:
- Always show annotation instructions and inter-annotator agreement.
- Report calibration set size and sampling strategy.
What the interviewer is really testing
They want to see that you can turn a fuzzy evaluation problem into a reproducible protocol with clear units, labeled data, and interpretable metrics. They are checking for practical tradeoffs: when to use automated signals, when to require humans, and how to report results so a product or research team can act on them.
Further reading in the curriculum
Go deeper on the fundamentals behind this question.
- Evaluating AI Systems How to measure, monitor, and improve LLM system quality from offline eval sets through production observability.
Related questions
How would you rate the quality of this article?
Prepare for your AI engineering interview
This is one of many detailed questions and explainers on StudyAIDesign. Browse the full set, work through the curriculum, and walk into your interview ready.