How to Test AI Hallucinations Step by Step
There is no single test that can identify every AI hallucination. A practical approach is to compare AI responses against trusted information, expected behavior, and clearly defined evaluation rules.
- How to Test AI Hallucinations Step by Step
- Step 1: Understand the AI Application
- Step 2: Prepare Reliable Reference Information
- Step 3: Create Different Types of Test Questions
- Step 4: Compare the AI Response with the Expected Answer
- Step 5: Check Whether the AI Invents Information
- Step 6: Test Whether the AI Admits Its Limitations
- Step 7: Repeat the Tests
- Step 8: Record and Report the Defect
Let’s understand the process step by step.
Step 1: Understand the AI Application
First, understand what the AI application is expected to do.
Ask questions such as:
- Is it a customer support chatbot?
- Does it answer questions using company documents?
- Does it generate software code?
- Does it summarize documents?
- Does it provide recommendations?
The testing approach depends on the application’s purpose.
For example, a chatbot that answers questions about company policies should be tested against approved policy documents.
Step 2: Prepare Reliable Reference Information
Before testing, collect the information that will be used to verify the AI’s answers.
Reference sources may include:
- Official product documentation
- Approved company policies
- Verified FAQs
- Trusted knowledge-base articles
- Expected outputs prepared by subject-matter experts
These sources help QA engineers determine whether the AI response is factually correct.
Important: The reference information must be accurate and up to date. Otherwise, the test itself may incorrectly classify a valid answer as a hallucination.
Step 3: Create Different Types of Test Questions
Do not test an AI chatbot using only simple questions. Prepare test inputs that represent different situations.
Include the following categories:
A. Questions with known answers
Ask questions for which the correct answer is available in the reference material.
Example:
Question: What is the company’s refund period?
Expected behavior: The chatbot should provide the refund period stated in the approved policy.
B. Questions with missing information
Ask something that is not covered by the available documents.
Example:
Question: What discount will the company offer next year?
Expected behavior: The chatbot should explain that the information is unavailable rather than inventing a discount.
C. Ambiguous questions
Ask questions that have more than one possible meaning.
Example:
Question: Which automation tool is best?
Expected behavior: The chatbot should ask about the user’s requirements or explain that the choice depends on the use case.
D. Questions containing incorrect assumptions
Include a false statement in the question.
Example:
Question: Why is Selenium a database management system?
Expected behavior: The chatbot should correct the assumption and explain that Selenium is used for browser automation.
E. Questions involving conflicting information
Provide conflicting statements in the available source material, where appropriate.
Expected behavior: The system should identify the conflict or communicate the uncertainty instead of confidently choosing an unsupported answer.
Step 4: Compare the AI Response with the Expected Answer
After submitting a question, compare the generated response with the trusted reference information.
Check the following:
- Are the facts correct?
- Are names, dates, numbers, and technical details accurate?
- Does the response contain information that is not supported by the reference?
- Has the AI changed the meaning of the source information?
- Does it clearly communicate when information is missing?
- Does the answer address the user’s actual question?
A response does not need to match the expected answer word for word. AI systems can express the same correct information in different ways.
The focus should be on factual accuracy, relevance, and support from reliable evidence.
Step 5: Check Whether the AI Invents Information
This step focuses on identifying fabricated details.
For example, ask the chatbot:
Question: Which official certification is required to use Playwright?
Suppose the chatbot responds that users must complete a fictional “Certified Playwright Professional” certification.
If no such requirement exists in the verified official documentation, the answer contains fabricated information.
The QA engineer should record the response, verify the claim against reliable sources, and classify the issue appropriately.
Step 6: Test Whether the AI Admits Its Limitations
A reliable AI application should not always attempt to answer every question.
Sometimes, the correct behavior is to say that the information is unavailable or that the system cannot verify a claim.
Example:
Question: What was our company’s total revenue yesterday?
If the AI application has no access to company revenue data, it should not invent a number.
Expected behavior: The system should clearly state that it does not have access to the required information.
This test helps verify whether the application handles missing information responsibly.
Step 7: Repeat the Tests
AI responses may change when the same question is submitted multiple times, especially when the system uses variable generation settings or frequently updated information.
Repeat important test cases to check whether the system produces consistent and acceptable answers.
Record any variation in factual accuracy, unsupported claims, or handling of uncertainty.
Not every wording difference is a defect. The concern is whether the variation introduces incorrect or misleading information.
Step 8: Record and Report the Defect
When you identify a hallucination, prepare a clear bug report.
Include:
- Test case ID
- Test question
- Expected behavior
- Actual AI response
- Reference source used for verification
- Steps to reproduce
- Severity and business impact
- Screenshot or response log, if available
A well-documented defect helps developers and AI engineers investigate the issue and improve the system.