How to Detect AI Hallucinations
Hallucinations are the failure mode where a model produces confident text that is not supported by evidence.
The model is not lying in any meaningful sense. It is doing what it was trained to do: predict tokens that continue a plausible sequence. When the training data is sparse or the retrieved context is missing or the reasoning chain drifts, the token predictions get creative. The output reads as fluently as everything else the model produces. The reader has no clear signal that this specific claim is invented while the one next to it is grounded.
Recent measurements put hallucination rates at 28 percent for DeepSeek-V3.1 and 27 percent for Gemini-2.5-Flash. Advanced training and retrieval augmentation reduce the rate. They do not eliminate it. The engineering discipline is detection at inference time, not elimination at training time.
Why This Is Not a Solvable Bug
The 2024 to 2026 research reframed hallucinations as a systemic incentive problem, not a bug to eradicate. Training objectives reward confident guessing over calibrated uncertainty. Benchmarks reward answering the question over admitting you do not know. Any model that gets trained on those incentives learns to produce confident answers whether or not the underlying knowledge is there.
This is why the goal has shifted from prevention to management. Detect hallucinations when they happen. Surface confidence signals to users. Route uncertain outputs to human review. Fall back to "I do not know" when the confidence is low enough. The engineering pattern assumes hallucinations will decline, not disappear.
Four detection families are practical in production. Each has different costs, accuracy characteristics, and integration profiles.
Retrieval-Based Detection
The most straightforward family. Every claim in the model output gets checked against a trusted external source. If the source supports the claim, it stays. If the source contradicts or does not mention the claim, it gets flagged.
This is the same category of check that RAG faithfulness metrics compute. The output is decomposed into individual claims. Each claim is compared against the retrieved context or against an external knowledge base. The score is the ratio of supported claims to total claims.
Strengths. When the external source is trustworthy, this is the strongest detection signal. Ground truth by design. No inference about model internals required.
Weaknesses. The external source must exist and must be current. For applications operating in domains where authoritative sources are hard to find or where the source itself may be outdated, retrieval-based detection catches nothing.
Best fit. RAG applications where the retrieval pipeline already produces grounded context. Legal research, medical Q&A, product-support agents grounded in current documentation.
Uncertainty-Based Detection
Every model output has an implicit confidence signal. Uncertainty-based methods extract that signal and use it as a proxy for hallucination risk. Low confidence, higher hallucination probability.
Three techniques dominate the family in 2026.
Sequence log-probability. Compute the log-probability the model assigned to the generated sequence. Low log-probability suggests the model was uncertain. This is the most-cited method because it requires nothing beyond the model's own token probabilities, but overconfident models produce misleading low-uncertainty signals on wrong answers.
Semantic entropy. Introduced in Nature by Farquhar et al. in 2024. Instead of measuring token-level uncertainty, cluster the model's possible answers by semantic meaning and compute entropy over the meaning clusters. High semantic entropy means the model would give different answers if sampled multiple times, which is a strong signal of unreliable knowledge. This is the current research state of the art.
Internal-state probes. Lightweight linear classifiers trained on the model's hidden layer activations to predict whether an output is likely to be a hallucination. Cheap at inference time once trained. Requires access to the model's internal states, which rules out closed API models.
Strengths. Zero external dependencies. Works in domains where retrieval-based checking is impractical. Scales to real-time inference.
Weaknesses. Uncertainty and correctness are not the same thing. A model can be confidently wrong when its parametric knowledge is systematically incorrect. Uncertainty-based methods miss those cases.
Best fit. Open-domain applications without external ground truth. Products where confidence surfacing is more important than absolute correctness.
Self-Consistency Detection
The insight: a model that knows an answer will give roughly the same answer when asked the same question multiple times. A model that is hallucinating will give inconsistent answers across samples.
The best-known implementation is SelfCheckGPT (Manakul et al., 2023). Generate multiple stochastic samples of the answer. Compare them for consistency using an LLM judge, natural language inference, or embedding similarity. Low consistency indicates hallucination.
Newer variants use more structured diversity techniques. Temperature Monte Carlo sampling varies the temperature across samples. LoRA-based ensembles train multiple lightweight adapters and combine their outputs. Semantically-equivalent prompt reformulations probe for consistency across paraphrased queries.
Strengths. Model-agnostic. Works with black-box APIs. Empirically strong signal on many classes of hallucination.
Weaknesses. Expensive. Every detection requires multiple model calls, which multiplies latency and cost. Prohibitive for high-volume real-time applications. Newer methods have reduced the cost but not eliminated it.
Best fit. Offline evaluation. Batch scoring. Systems where a slower, more reliable check is worth the additional cost.
Learning-Based Detection
Train a dedicated classifier to identify hallucinations. Feed it labeled examples of hallucinated and non-hallucinated outputs. Deploy it as a lightweight second model that runs after the primary generation.
Strengths. Fast at inference time. Can be tuned to specific hallucination patterns that matter for a particular application. Can incorporate features other methods miss.
Weaknesses. Requires labeled training data, which is expensive to produce. The classifier's accuracy depends on how well the training distribution matches production distribution. Performance can degrade silently when the primary model updates or the input distribution shifts.
Best fit. Mature production systems with enough hallucination data to train on, and enough investment budget to maintain the detector as the primary model evolves.
What Ships in Production Today
Most production teams do not pick one family. They stack.
The common pattern is retrieval-based detection as the first layer wherever ground truth is available, uncertainty-based signals as a second layer to catch cases the retrieval layer missed, and human review or fallback behaviors triggered when either layer flags high risk.
Enterprise platforms have started shipping trained hallucination detectors as a service. Galileo's Luna-2 offers full-traffic evaluation at sub-200ms latency and 97 percent lower cost than the previous generation. Arize Phoenix ships hallucination scoring among its 50-plus built-in metrics. Confident AI runs hallucination detection on every trace step in production. These platforms make sophisticated detection available without requiring in-house research infrastructure.
The one thing production teams have converged on: detection at generation time, not detection after the user complains. A hallucination that reaches the user is more expensive than a hallucination that gets caught by the detection layer and turned into a fallback response or a human-review escalation.
The Failure Mode Every Detector Shares
All four detection families make one assumption that fails in a specific class of cases. They assume the source material the model is generating from is trustworthy.
Retrieval-based methods verify against retrieved context or an external source. If the retrieved context or the external source is stale, contradictory, or wrong, the method scores the output as faithful when the underlying claim is factually incorrect. The detector passes. The user gets a wrong answer.
Uncertainty-based methods measure the model's confidence in its output given its training and its input. A model trained on outdated data can be confidently wrong on current facts. The uncertainty signal reads low. The detector passes. The user gets a wrong answer.
Self-consistency methods measure agreement across samples. A model with a stable but incorrect belief will produce consistent samples that agree with each other and disagree with reality. The detector passes. The user gets a wrong answer.
Learning-based methods depend on the training distribution matching the production distribution. When source material shifts or when the model gets updated, the classifier's calibration drifts silently. The detector passes. The user gets a wrong answer.
This is the trust-layer problem hallucination detection alone cannot solve. Detection catches outputs that fail internal consistency checks. It does not catch outputs where the model, the retrieval, and the source material all agree on the wrong answer.
Where to Start
If a team has never done hallucination detection, three steps get to a working baseline.
Add retrieval-based detection as the first layer. If the application uses RAG, add a faithfulness check on every output. Use RAGAS, DeepEval, or a similar framework. The detection is cheap and catches the largest class of hallucinations.
Add an uncertainty signal as the second layer. Log-probability is the cheapest. Semantic entropy is the strongest but requires multiple samples. Pick the one that matches the application's latency budget.
Route flagged outputs somewhere useful. A caught hallucination that just gets logged and forgotten is not detection, it is theater. Flagged outputs need to trigger a fallback response, a human review, an "I do not know" answer, or a retry with different context. The action on the flag is what makes detection matter.
That is the minimum viable hallucination detection. Everything beyond it is refinement.
Structure before tools. Strategy before speed. Systems before scale.
Detection catches the model. Trust catches the source. The AI systems that stay reliable in production do both.
The AI Operator Framework is the operator playbook for shipping AI work that compounds. Read the framework here or take the course.