Hallucinations
Hallucinations come in two kinds: the answer contradicts the provided source, or the model invents a fact where there is no source. The first is measured as the share of claims supported by the context (faithfulness in RAG), the second with out-of-context questions where a refusal or handover is expected. RAG reduces the risk but does not remove it; the judge model is calibrated on human labels, and excessive refusals are measured.
QA Fundamentals · AI in testing
A bot confidently promised a refund within 30 days, while the policy says 14. How do you catch that with a test?
A support agent with a knowledge base answers customers. The answer looks perfect: polite, structured, with a specific figure. But the figure does not match the policy, and the next day a customer comes for the money. Who would catch this without a dedicated check? The basic definition of a hallucination is given in the lesson on why AI answers cannot be taken as is; here is how to classify them and hunt for them in a feature.
How it works and why. A model is trained to continue text plausibly, not to refuse. When the needed fact is missing from the context or the model did not "notice" it, the likeliest continuation is a familiar-looking answer and not "I do not know". So hallucinations have two roots that are tested differently. The first: the answer contradicts the provided source (in RAG this is a faithfulness problem). The second: the source says nothing and the model fills the gap with an invention. RAG lowers the risk because it gives the model something to lean on, but does not remove it: the answer may lean on the wrong fragment, join two fragments wrongly or add its own "detail".
Two different kinds of error
context says 14 days, the answer says 30
Checked by comparing the answer with the provided context: is every claim supported by it.
nothing about a discount, yet the bot names a percentage
Checked by questions outside the context: the right answer is "I do not know" or a handoff to a person.
Example: an error of the first kind.
Context (from the knowledge base):
"A refund is possible within 14 days of the purchase date."
Question: Can I return an item after 29 days?
Bot answer: "Yes, a refund is possible within 30 days."
How to read it. The answer does not invent a new category, it distorts an existing figure, which is why it sounds good. A comparison with the context gives the verdict: the claim "30 days" is not in the source, while 14 is. For a manual check that is enough. For an automatic one, each claim of the answer is split out and checked for support by the context: an LLM judge does this and the metric is called faithfulness. The second kind is checked by a provocation:
Question: Is there a student discount?
Context: nothing about student discounts.
Expected: "This is not in the available materials, I will pass the question to an operator."
Bad: an invented discount, percentage or condition.
Such out-of-context questions must be in the set next to ordinary ones: they catch what ordinary questions do not reveal. An extra check: links, quotations and names the model cited really exist. Metrics at the level of the set: the share of supported claims and the share of correct refusals where there is no answer.
Limits and alternatives. An LLM judge can be wrong too, so its verdicts are compared with human labels on a sample. A comparison with the context will not find an error if the context itself (a knowledge-base article) is outdated or wrong: the source needs checking. Refusing also has a price: a bot that answers "I do not know" to everything is safe but useless, so the share of answers to questions that had an answer is also measured. For critical answers (money, health, law) add hard rules: a citation of the source next to the answer or a handoff to a person. This does not replace checks, it reduces the cost of a miss.
Common mistakes.
- Checking only questions that have an answer: a bot that invents where there is no answer goes unnoticed.
- Judging by "sounds right": hallucinations are persuasive, so check against the source.
- Treating RAG as a guarantee: the model can still distort or embellish.
- Trusting an LLM judge without calibrating it on human labels.
- Not checking the source for staleness: the bot will faithfully retell an old policy.
Check yourself
A bot cited a knowledge-base article in its answer and the test only checks that a link is present. Why is that not enough?
Answer
Because the link may lead to a non-existent article or to one that does not support what was said. Check that it opens and that the claim really follows from its content.
Every question in the set has an answer in the knowledge base and faithfulness is 98%. What does this figure hide?
Answer
Behaviour where there is no answer: the bot might invent, and the set does not check that. Out-of-context questions are needed, expecting "I do not know" or a handoff to a person.