Measuring hallucination & groundedness

In one sentence

Split the answer into atomic claims, check each against the provided context with an NLI model or LLM judge, and report the unsupported share per slice. Faithful-to-context is not the same as factually true.

Analogy: A fact-checker with a highlighter: for every sentence in the article, find the line in the source notes that backs it. Sentences left without a highlight are the hallucinations, even if they happen to be true.

Verification is per claim, so one invented figure inside a long, mostly correct answer is still caught.

How it works

  • Groundedness asks whether each claim is supported by the context you gave; factuality asks whether it is true.
  • An answer can be faithful but wrong (stale document) or correct but ungrounded (from model memory).
  • RAGAS faithfulness is supported claims ÷ total claims; hallucination rate is the share of answers with ≥ 1 unsupported claim.
  • Vectara HHEM, a small open classifier, is cheap enough to score every request.
  • Averages hide failures: 3% overall can hide 20% on tables, so slice by document type and language.

Check yourself

Answer to mark it learned; your answers aren't scored.

Your benefits assistant scores 0.94 average faithfulness on the eval set, yet users keep reporting wrong figures in answers about plan tables. What's your first move?

Go deeper

Full explanation

Two questions hide under "hallucination":

  • Groundedness / faithfulness — is every claim supported by the context you gave the model (retrieved docs, tool results)? Checkable without knowing the truth; it's what RAG and agents need.
  • Factuality — is it true in the world? Needs a trusted reference or experts.

An answer can be faithful but wrong (stale document) or correct but ungrounded (from model memory) — still a bug in a system that must answer from its sources.

The standard recipe is claim decomposition + verification:

  1. An LLM splits the answer into atomic, self-contained claims.
  2. An NLI model (entailment classifier) or an LLM-as-a-judge checks each claim against the context.
  3. RAGAS faithfulness = supported claims ÷ total claims. Answer-level hallucination rate = share of answers with ≥ 1 unsupported claim.

Other tools:

  • Vectara HHEM — a small open classifier scoring (source, claim) consistency; cheap enough for every request.
  • SelfCheckGPT — no context? Sample the answer several times; claims that don't recur across samples are likely invented.
  • Citation checks — does each cited passage actually entail its sentence (Citations & grounding)?

Report per slice (document type, language, empty retrieval, numeric questions): a 3% average can hide 20% on tables.

Code Claim-level faithfulness with HHEM, reported per slice
pythonClaim-level faithfulness with HHEM, reported per slice
import pandas as pd
from transformers import AutoModelForSequenceClassification

# HHEM: small open classifier; scores (premise, hypothesis) from 0 (unsupported) to 1
hhem = AutoModelForSequenceClassification.from_pretrained(
    "vectara/hallucination_evaluation_model", trust_remote_code=True)

def check(context: str, answer: str, threshold: float = 0.5) -> dict:
    claims = extract_claims(answer)   # LLM call: atomic, self-contained claims
    if not claims:                    # e.g. "I don't know": track abstention separately
        return {"faithfulness": None, "hallucinated": False, "unsupported": []}
    scores = hhem.predict([(context, c) for c in claims]).tolist()
    unsupported = [c for c, s in zip(claims, scores) if s < threshold]
    return {
        "faithfulness": 1 - len(unsupported) / len(claims),  # RAGAS-style ratio
        "hallucinated": bool(unsupported),                   # answer-level flag
        "unsupported": unsupported,                          # what a human should read
    }

rows = [check(r.context, r.answer) | {"slice": r.doc_type} for r in eval_set]
report = pd.DataFrame(rows).groupby("slice").agg(
    faithfulness=("faithfulness", "mean"),
    hallucination_rate=("hallucinated", "mean"),
    n=("hallucinated", "size"),
)
print(report.sort_values("hallucination_rate", ascending=False))  # worst slice first
Real example

A benefits assistant scores 0.94 faithfulness on 500 eval questions — looks fine. Sliced by source type, answers built from PDF tables score 0.71: the parser flattened the columns, so the model "repairs" numbers from memory, and 38% of those answers contain at least one unsupported claim. Fixing table parsing lifts the slice to 0.93. A nightly HHEM check on 5% of production answers now alerts when any slice falls below 0.9, and flagged claims go to a reviewer queue.

Trade-offs +3 · −3

+ You gain

  • Checks grounding without knowing the true answer, so it scales to production traffic.
  • Claim-level output points at exactly which sentence was invented.
  • NLI classifiers like HHEM are cheap enough to run on every response.

− You pay

  • Claim extraction and verification are themselves model calls that make mistakes.
  • Blind to wrong-but-faithful answers built on bad or stale context.
  • Struggles with numbers, tables, multi-hop reasoning and very long contexts.

Use it when

RAG, summarization, extraction and agents answering from tool results — anywhere the output must be backed by a given source. Run it offline on the golden set and online on sampled traffic.

Avoid it when

Creative or open-ended tasks, or factual questions with no source to check against: there you need reference answers, SelfCheckGPT-style consistency or experts.

Numbers to know 3
  • RAGAS faithfulness = claims supported by the retrieved context ÷ total claims in the answer (0–1).
  • FActScore (Min et al., 2023): only ~58% of the atomic facts in ChatGPT-generated biographies were supported.
  • Vectara HHEM scores each (source, claim) pair from 0 (hallucinated) to 1 (consistent); 0.5 is a common cut-off; tune it on labeled data.
Common pitfalls 4
  • Treating faithfulness as correctness: a perfectly grounded answer from a stale document is still wrong.
  • Verifying the whole answer at once instead of per claim: one invented figure hides in a long reply.
  • Trusting the verifier without calibrating it on human-labeled hallucinations.
  • Scoring "I don't know" as a failure: abstaining when evidence is missing is correct; track it separately.
Interview questions 2

Answer out loud first, then reveal.

How would you measure hallucination in a RAG system?Show answer

First I separate faithfulness from correctness. For faithfulness, I decompose each answer into atomic claims and check each against the retrieved context: an NLI model like HHEM for cheap coverage of sampled production traffic, and a calibrated LLM judge offline. I report claim-level faithfulness and answer-level hallucination rate per slice, worst slice first. For correctness I compare against reference answers in the golden set. And I include unanswerable questions, because the right behavior there is to abstain, and that's where most invention happens.

There's no retrieved context: the model answers from memory. How do you detect hallucinations?Show answer

Without a source I can't measure grounding, so I use proxies. SelfCheckGPT-style consistency: sample the answer several times at non-zero temperature and flag claims that don't recur, since invented facts tend to vary while known ones repeat. Offline, I measure factuality against a reference set with claim-level scoring like FActScore. But the better fix is architectural: give the model a source through retrieval or a tool, so the question becomes groundedness, which I can measure on every answer.