Hallucination and Groundedness Testing
A hallucination is an answer from a language model that states something false or unsupported as if it were fact: an invented refund rule, a wrong date, a citation to a section that does not exist. NIST AI 600-1 calls this risk confabulation: confidently stated but false content. Hallucination testing is the deliberate search for such answers before users meet them.
Groundedness is the part you can check. An answer is grounded when every factual claim in it is supported by the sources the system gave the model: retrieved documents, a database record, a tool result. A returns assistant that is given a policy saying 14 days and replies "30 days" is ungrounded, however natural the answer sounds.
Why it matters
Hallucinated answers are fluent and confident, so people act on them: they rely on a deadline, a price or a policy that does not exist. The OWASP Top 10 for LLM Applications 2025 lists misinformation (LLM09) as a risk and names hallucination as one of its main causes. For the product, that means wrong decisions, complaints and liability.
For a tester, hallucination breaks the usual oracle: the output looks plausible, changes between runs, and one passing run proves little. A language model generates likely text, not checked facts, so no prompt makes hallucination impossible. Your job is to measure how often and where it happens and to verify the safeguards: sources, citations, refusals. Testing shows the presence of defects, not their absence.
Two reference points and the shapes hallucination takes
First decide what you check an answer against. In a closed-book setting the model answers from its training, so you need an external reference. In a grounded setting — retrieval-augmented generation (RAG), an uploaded document, a tool result — the system hands the model its sources, and you check the answer against exactly those.
The two checks can disagree. An answer can be true but ungrounded: the model answered from memory, which works until its memory is wrong or outdated. It can also be grounded but false: it faithfully repeats an outdated document — a data defect, not a model defect.
- Fabricated entities: a product, policy section, API function, person or URL that does not exist.
- Wrong specifics: numbers, dates, prices or names altered, or mixed up between sources.
- Contradiction: the answer says the opposite of its source.
- Unsupported additions: a plausible extra promise, such as "return shipping is free", that no source contains.
- Accepted false premises: explaining "why the Basic plan includes phone support" when it does not.
Groundedness: check the answer claim by claim
A whole answer is too coarse to judge. Split it into atomic claims — single statements that are either supported or not — and label each against the sources: supported, contradicted or not found. "Not found" matters as much as "contradicted": an unsupported claim is a hallucination even when it happens to be true.
Fix the context in your test cases: give the model a known set of passages, not whatever retrieval returns today, so that a failure points at generation and can be reproduced.
A groundedness rate shows trends across a test set. Per claim, it is supported claims divided by all factual claims, as the Ragas research paper computes its faithfulness score with a language model as the checker; some teams count fully supported answers instead. For a single high-stakes case, use an acceptance rule: one contradicted or not-found claim fails it.
- Code checks what is exact: numbers, IDs and quoted strings appear in the source; every cited ID exists and was provided. When answers are structured JSON, a schema can require a citation for every claim.
- Human reviewers judge meaning with a written rubric. A model-based grader can scale this only once its labels match human labels on your data, because it can hallucinate too.
Worked example: a returns assistant
A shop’s support assistant answers from the returns policy, which the system passes to the model as its only context. The honest answer to the test question is "no": questions that invite a friendly "yes" from general knowledge are where grounding breaks.
The labelled answer below fails although part of it is correct. A grounded answer: "No. Sale items cannot be returned (rule 3). Other unused items can be returned within 14 days of delivery (rule 1)."
Context given (policy-returns v3):
"1. Unused items can be returned within 14 days of delivery.
2. Refunds go to the original payment method within 5 business days.
3. Sale items cannot be returned."
Question: Can I return a sale item I bought last week?
Answer under test:
"Yes. You can return any item within 30 days of delivery, as stated
in section 4 of our policy. The refund goes back to your original
payment method within 5 business days."
Claim Label Source
C1 A sale item can be returned contradicted rule 3
C2 The return window is 30 days contradicted rule 1
C3 The policy has a section 4 not found -
C4 Refund to original payment method supported rule 2
C5 Refund within 5 business days supported rule 2
Result: FAIL - 2 of 5 claims supported, 2 contradicted, 1 not foundHallucinated answerAnswer under testFail
"Yes. Any item within 30 days, as stated in section 4. Refund to your original payment method within 5 business days."
- Sale items:
- "Can be returned": contradicted by rule 3Fail
- Return window:
- 30 days: contradicted by rule 1 (14 days)Fail
- Reference:
- "Section 4": not found, the policy has rules 1 to 3 onlyFail
- Refund details:
- Original payment method, 5 business days: supported by rule 2Pass
- Test result:
- Fail: 2 of 5 claims supported, 2 contradicted, 1 not foundFail
Grounded answerExpected behaviourPass
"No. Sale items cannot be returned (rule 3). Other unused items within 14 days of delivery (rule 1)."
- Sale items:
- "Cannot be returned": supported by rule 3Pass
- Return window:
- 14 days for other unused items: supported by rule 1Pass
- Reference:
- Rules 3 and 1: exist and support the sentences they followPass
- Refund details:
- Not mentioned: not needed to answer this question
- Test result:
- Pass: every claim supported by the policyPass
Question: "Can I return a sale item I bought last week?" Context: policy-returns v3, rules 1 to 3.
Fact-checking when there is no single source
Closed-book answers, and the general-knowledge parts of grounded answers, need a different oracle. Build it before you test, or the most confident answer will set your expectation; store it in the test set, for example as one JSON Lines record per question.
- Reference answers verified by a domain expert, listing the facts that must and must not appear.
- Authoritative sources: the product’s database, official documentation or the standard itself — never another model’s answer.
- Deterministic checks: links resolve, cited documents exist, totals recompute, named API functions exist.
- Consistency as a signal: ask the same question repeatedly and in paraphrased forms; facts that change point to guessing. But a model can also repeat the same wrong answer every time.
- Trap questions: a near-identical product, an old version, or a detail that sounds standard but differs in your domain.
Unanswerable questions: test the right to say "I don’t know"
Add unanswerable questions to your test set with the expected behaviour: a clear statement that the information is not available, no invented detail, no citation and, where offered, a route to a human.
Track two rates together: invented answers to questions that cannot be answered, and inappropriate refusals of questions that can. A system that refuses everything never hallucinates and is useless, and a prompt change that lowers invented answers can raise refusals.
- Not in the sources: plausible questions that the documents do not cover.
- False premise: the question assumes something untrue; the answer should correct it.
- Partly answerable: answer what the sources support and say what is missing.
- Answerable controls: these must be answered; a refusal here is an inappropriate refusal.
Common mistakes
- Judging an answer by how convincing it reads instead of checking each claim against a source.
- Running a case once and treating one pass as proof, although outputs vary between runs.
- Making another language model the only fact-checker without comparing it with human labels.
- Counting invented answers without counting inappropriate refusals.
- Blaming the model when the retrieved passage or the source document was wrong.
The QA perspective
On a real team, hallucination testing starts with the product owner: which topics are high-stakes, which sources are authoritative, and what the assistant says when it does not know. Write the answers down as testable acceptance criteria, such as "every price in an answer matches the catalogue".
Keep a versioned test set of answerable, unanswerable and false-premise questions with their sources, and run it on every prompt, model or source change. A hallucination report needs the input, the context given, the prompt and model versions, each failed claim with its label and source text, and how many runs reproduced it. Retrieval, prompt, model and source data each need a different fix, so find the cause with the developers.
Practice exercise
Label the claims in an assistant’s answer
A mobile operator’s help assistant receives only the source below as context. Check its answer claim by claim, decide whether the test case passes, and write a grounded answer.
Then write three more test questions for the same source — unanswerable, false premise and answerable control — with the expected behaviour of each.
Context given (plan-faq v2):
"The Traveller add-on gives 5 GB of roaming data valid for 7 days.
It costs 49 SAR and works in GCC countries only.
Unused data does not carry over."
Question: How much roaming data do I get in Egypt with Traveller?
Answer under test:
"You get 5 GB of roaming data in Egypt, valid for 30 days, for
49 SAR. You can renew it any time from the app, and data you do
not use carries over to your next add-on (plan-faq v2)."- Split the answer into single, checkable claims.
- Label each claim: supported, contradicted or not found.
- Check the citation: does it exist, was it provided, does it support its claims?
- Decide pass or fail, and write a grounded answer.
Show the model answer
Claims: C1 works in Egypt — contradicted (GCC countries only). C2 5 GB of roaming data — supported. C3 valid for 30 days — contradicted (7 days). C4 costs 49 SAR — supported. C5 renewable any time from the app — not found. C6 unused data carries over — contradicted.
The citation exists and was provided, but it contradicts three of its claims, so it makes the answer look checked when it is not. Result: fail, 2 of 6 claims supported.
The question itself has a false premise (that Traveller works in Egypt), so a grounded answer corrects it first: "Traveller does not cover Egypt: it works in GCC countries only, where it gives 5 GB for 7 days for 49 SAR; unused data does not carry over (plan-faq v2). For roaming in Egypt, please contact support."
Extra questions. Unanswerable: "Is there an add-on that covers Egypt?" — says the information is not available, offers support, names no plan. False premise: "Why does my unused Traveller data carry over?" — corrects the premise. Control: "How long is Traveller data valid?" — "7 days", citing plan-faq v2.
Frequently asked questions
Can a better prompt eliminate hallucinations?
No. Instructions such as "answer only from the sources" and "say when you do not know", together with grounding through retrieval, can reduce them, but a language model still generates likely text rather than verified facts. Measure the rate on your own test set before and after each change, and keep the safeguards: sources, citations, refusals and human review for high-stakes answers.
What is the difference between groundedness and correctness?
Groundedness asks whether each claim is supported by the sources the system was given; correctness asks whether it is true according to a trusted reference. They differ when the source is wrong or outdated (grounded but false) or when the model answers correctly from memory (true but ungrounded). Test both where the product depends on both.
Can a public benchmark tell me whether my assistant hallucinates?
Not directly. Research benchmarks such as TruthfulQA probe whether models repeat common misconceptions, which helps when comparing models. They do not test your product, your sources or your users’ questions; that needs your own test set.
Is a high faithfulness score enough to release?
Not on its own. A score computed by a model grader inherits that grader’s errors, and an average hides the single critical failure. Use scores for trends, check them against human labels on your own data, and pair them with acceptance rules for high-stakes cases, as described in the guide on LLM evaluation.
References
- Artificial Intelligence Risk Management Framework: Generative Artificial Intelligence Profile (NIST AI 600-1)The generative-AI profile of the AI RMF: risks specific to generative models, such as confabulation and information integrity, and suggested actions to manage them.
- OWASP Top 10 for LLM Applications 2025The ten most critical security risks of LLM applications (LLM01:2025–LLM10:2025), starting with prompt injection and sensitive information disclosure.
- Ragas: Automated Evaluation of Retrieval Augmented Generation (Es et al.)Research proposing reference-free metrics for RAG pipelines, such as faithfulness, answer relevance and context relevance.
- TruthfulQA: Measuring How Models Mimic Human Falsehoods (Lin, Hilton, Evans)A research benchmark of questions designed to reveal whether a model repeats common misconceptions instead of answering truthfully.
Practise with Mutqan tools
Compare two texts line by line or word by word and highlight differences.
Validate a JSON document against a JSON Schema (draft-07 / 2019-09 / 2020-12 core keywords).
Validate every line of a JSON Lines file and report the exact failing lines.
Compare two JSON documents semantically and highlight added, removed and changed values.
Go deeper
- RAG Testing: Retrieval, Grounding, CitationsTesting generation: groundedness and answer relevance
- RAG Testing: Retrieval, Grounding, CitationsWhen the answer is not in the corpus
- LLM Evaluation: How to Evaluate LLM OutputsStep 4: choose graders — code, human, model
- LLM Testing: How to Test LLM ApplicationsAI quality metrics and their limits
Your progress on this topic
Not started
Mark the topic complete when you have studied it and done the exercise.
Sign in to track your progress
Mark topics complete, continue where you left off and unlock specialisation exams.