Prompt
How do I measure hallucinations in a chatbot response?
Latest observation
To measure hallucinations in a chatbot response, you first need to define what counts as hallucination in your setting:
- Factual hallucination: the model states something false or unsupported.
- Context hallucination: it invents details not present in the conversation, retrieved docs, or system prompt.
- Attribution hallucination: it claims a source, quote, or action that didn’t happen.
Practical ways to measure it
1) Human annotation
Have reviewers label each response or each claim as:
- Supported
- Unsupported / hallucinated
- Contradicted
- Unclear
Then compute metrics like:
- Hallucination rate = hallucinated claims / total claims
- Precision of factual statements = supported claims / all claims
- Error severity = weight high-impact mistakes more than minor ones
This is the most reliable method, especially for high-stakes use cases.
2) Claim-level checking
Break responses into atomic factual claims, then verify each against:
- trusted knowledge sources
- retrieved documents
- conversation context
- external databases or APIs
Example response:
“Paris is the capital of France, and it has a population of 20 million.”
Split into claims:
- Paris is the capital of France — supported
- Paris has a population of 20 million — maybe false depending on source
Then measure the fraction that are unsupported or false.
3) Faithfulness / groundedness metrics
If the chatbot uses retrieval-augmented generation, measure whether the answer is grounded in the provided context.
Common metrics:
- Answer relevance: did it answer the question?
- Context precision: how much of the response is supported by context?
- Context recall: did it use the relevant context?
- Faithfulness score: percentage of statements entailed by the source text
Tools/frameworks that help:
- RAGAS
- TruLens
- DeepEval
- LangSmith evals
- OpenAI Evals or custom evals
4) LLM-as-judge
Use another model to evaluate whether each statement is supported by references.
Good for scale, but:
- can miss subtle errors
- may itself hallucinate
- should be calibrated against human labels
Best practice: use it as a proxy, not the sole source of truth.
5) Task-specific accuracy
For certain domains, hallucination can be measured indirectly by exact correctness:
- customer support: correct policy references
- medical/legal: verified citations
- coding: tests pass / code runs
- retrieval QA: exact match or semantic similarity against gold answers
A simple evaluation workflow
- Collect a set of prompts and expected sources.
- Generate chatbot responses.
- Split responses into factual claims.
- Verify each claim against trusted evidence.
- Label each claim supported/unsupported/contradicted.
- Compute:
- hallucination rate
- unsupported claim rate
- severity-weighted error rate
- Review errors by category:
- invented facts
- wrong numbers
- made-up citations
- wrong attribution
- context drift
Good metric definitions
If you want one simple metric, use:
Hallucination rate = unsupported claims / total factual claims
If you want a more nuanced one:
Weighted hallucination score = sum(severity × unsupported claim indicator) / total claims
Where severity might be:
- 1 = minor detail error
- 3 = important factual error
- 5 = safety-critical falsehood
Important caveats
- A response can be partly correct and partly hallucinated.
- Some “hallucinations” are actually outdated facts or ambiguous questions.
- You need a clear ground truth or source of truth to measure reliably.
If you want, I can help you design a hallucination evaluation rubric or a Python script to score chatbot outputs automatically.