How to Measure AI Hallucinations

QA engineers can use measurable indicators to understand how often a system produces unsupported or incorrect information.

1. Hallucination Rate

For a test set with clearly defined evaluation rules, calculate:

Hallucination Rate = (Responses containing hallucinations ÷ Total evaluated responses) × 100

Example:

Suppose you evaluate 100 AI responses and identify 12 responses containing hallucinations.

Hallucination rate = (12 ÷ 100) × 100 = 12%.

This means 12% of the evaluated responses contained at least one identified hallucination.

The result depends on the test data, evaluation method, and definition of a hallucination. It should not automatically be treated as the application’s overall real-world error rate.

2. Factual Accuracy

Factual accuracy measures how many evaluated factual claims are correct according to reliable reference information.

For example, if 90 out of 100 evaluated factual claims are correct, factual accuracy is 90%.

A response may contain multiple factual claims, so this metric is different from measuring the percentage of completely correct responses.

3. Groundedness

Groundedness measures whether the claims in an AI response are supported by the supplied context or reference sources.

For example, if a chatbot uses company policy documents, check whether its claims can be supported by those documents.

A response can be grounded in a document and still repeat an error present in that document. Therefore, groundedness and factual accuracy should be evaluated separately.

4. Appropriate Abstention

This measures whether the AI system correctly declines to provide a definite answer when the required information is missing or cannot be verified.

For example, if the chatbot receives 20 questions that cannot be answered from its available data, check how often it correctly communicates the limitation instead of guessing.

A strong evaluation should also check that the system answers questions when sufficient reliable information is available. Excessive refusals are not a good outcome.

Example: Testing Hallucinations in an AI Customer Support Chatbot

Imagine a company has developed an AI chatbot to answer customer questions about its return policy.

The approved policy states:

The QA engineer prepares the following tests.

Test 1: Valid question

Input: Can I return a product within 10 days of delivery?

Expected: The chatbot explains the applicable return conditions and confirms that 10 days falls within the 14-day return period.

Test 2: Invalid time period

Input: Can I return a product after 25 days?

Expected: The chatbot explains that 25 days falls outside the standard 14-day period, while mentioning any applicable exceptions only if supported by the policy.

Test 3: Missing information

Input: Will my refund arrive in exactly two hours?

Expected: The chatbot provides the documented processing time if available. Otherwise, it explains that it cannot confirm an exact two-hour refund.

Test 4: Fabricated policy

Input: Does the company provide a 90-day return guarantee?

Expected: The chatbot should not confirm a 90-day guarantee unless the approved information supports it.

By executing these tests, the QA engineer can identify incorrect policy details, unsupported promises, and poor handling of missing information.

Useful Techniques and Tools for AI Hallucination Testing

QA engineers can combine manual testing, automated checks, and specialized evaluation methods.

1. Manual Testing

Manual testing is useful when you are starting with AI testing.

Prepare a set of questions, review the responses, compare them with reference sources, and document the defects.

This method is particularly useful for understanding how the AI behaves before building an automated evaluation process.

2. Automated Test Scripts

Automation can execute a collection of predefined questions and store the generated responses for evaluation.

For example, a test script can submit 100 questions to an AI API, save the responses, and compare exact fields such as product names, dates, or approved policy values.

However, automated scripts cannot reliably detect every type of hallucination through simple text matching. More flexible evaluation rules may be needed for open-ended responses.

3. LLM-as-a-Judge Evaluation

An LLM-as-a-judge approach uses another language model to evaluate an AI-generated response against a reference answer or supporting context.

The evaluator can assess factual support, relevance, completeness, and unsupported claims.

This technique can help process large numbers of responses, but the evaluating model can also make mistakes. Important results should be validated using trusted reference information and human review.

4. RAG Evaluation Tools

Retrieval-Augmented Generation (RAG) applications retrieve relevant documents before generating an answer.

Tools and frameworks such as Ragas can help evaluate aspects of RAG applications, including answer relevancy, faithfulness, and retrieval quality.

These evaluations can help identify whether an AI response is supported by the retrieved context. They do not guarantee that every answer is factually correct.

QA engineers can use frameworks such as Ragas to evaluate aspects of AI-generated responses, including faithfulness and relevance. These metrics help identify potential problems, but they do not guarantee that every answer is factually correct.

5. Maintain a Regression Test Dataset

Whenever an important hallucination is discovered, add the question and its expected behavior to a reusable regression test dataset.

Run the dataset after changes to prompts, models, retrieval logic, or reference documents.

This helps teams identify whether a new change fixes an existing issue or introduces a new one.

Common Challenges in AI Hallucination Testing

Testing AI systems is different from testing traditional applications because answers can vary in wording and structure.

Here are some common challenges.

Different answers to the same question: AI responses may vary between runs. Evaluate whether the facts remain correct instead of requiring identical wording.

No single expected answer: Open-ended questions may have several valid responses. Define evaluation criteria and trusted reference material rather than relying only on exact text matching.

Difficulty verifying facts: Some claims require technical expertise or access to authoritative documentation.

Large volumes of responses: Manual evaluation becomes time-consuming as the test dataset grows. Automation and sampling can help, but high-risk outputs still need careful review.

Changes over time: Models, prompts, knowledge bases, and retrieval systems can change. Regression testing is necessary to detect new problems.

Understanding these challenges helps QA engineers create more useful and realistic AI testing strategies.

Best Practices for Testing AI Hallucinations

Follow these practices to improve your AI testing process:

  1. Use reliable and updated reference information.
  2. Include positive, negative, ambiguous, and out-of-scope questions.
  3. Test numbers, dates, product names, and other important factual details.
  4. Check whether answers are supported by the available context.
  5. Verify that the AI handles missing information appropriately.
  6. Use repeatable evaluation criteria.
  7. Automate repetitive checks wherever practical.
  8. Use human review for high-risk or difficult-to-verify responses.
  9. Maintain regression test cases for previously identified defects.
  10. Track results over time and investigate significant changes.

For applications used in healthcare, finance, legal services, or other high-impact areas, prioritize risk-based testing and appropriate expert review.

Pages: 1 2 3 4 5

Leave a Reply

Your email address will not be published. Required fields are marked *