How do you test features built on LLMs (a chatbot, an assistant)?
Testing an LLM feature checks the properties of an answer, not the exact text, because token choice is probabilistic. A case is a request, criteria (facts, forbidden content, format, boundaries, behaviour on the unknown, security) and a threshold, and the request runs as a series with the success share counted. The query set is rerun as a regression after every prompt, model or knowledge base change, and production bugs join it.
QA Fundamentals · AI in testing
A chatbot test passes and fails on the same question. Is it a bug in the bot or in the test?
A support chatbot was added to the app. QA writes a test: the question "What is the transfer fee?" and a comparison of the answer with an expected text. In the morning the test is green, in the evening red, though nothing in the bot changed: the answer means the same, but the words are different. The usual approach "expected equals actual" does not work here. The lesson covers how testing an LLM feature differs from usual testing and what a check consists of.
How it works and why. In an LLM feature the answer is built from a probabilistic choice of tokens, so the exact text is not a stable result. What can be stable is the properties of the answer. So a test case consists of an input request and criteria, not a reference text. Besides, the feature has more sources of change than a usual one: not only code changes but also the prompt, the model, the settings and the knowledge base the bot takes facts from. Any of these can break behaviour, so the set of requests is run after each such change, as a regression.
| What we check | Example |
|---|---|
| Usefulness and facts | The key facts from the knowledge base are there, the fee number is right |
| Forbidden content | No made-up numbers, no other people's personal data, no advice outside the bot's role |
| Format and language | The question's language, size, structure if the interface expects it |
| Boundaries | For an off-topic question the bot politely declines, and it does not perform actions without confirmation |
| Uncertainty | If the answer is not in the knowledge base, the bot says "I don't know" or hands over to a human |
| Security | Attempts to make it ignore its instructions (prompt injection) do not work |
| Non-functional | Response time, request cost, behaviour when the model is unavailable |
One bot answer and two ways to check it
Compare with a reference string
The answer is worded differently each time, so the test passes and fails at random. The team stops trusting it.
Check properties
The needed facts are present, the forbidden ones are absent, the language and format are right. Different wording does not break the test.
Example: from a string comparison to a case with criteria. The original test compared the answer with the string "The fee is 1%, minimum 5 UAH". A version where the same answer is retold in other words breaks it. The reworked case describes criteria and allows a spread:
{
"id": "fee-01",
"input": "What is the fee for a card transfer?",
"must_include": ["1%", "5 UAH"],
"must_not_include": ["no fee", "0 UAH"],
"language": "en",
"max_sentences": 4,
"runs": 10,
"min_pass_rate": 0.9
}
The case reads like this: the answer must contain the facts about 1% and 5 UAH, must not claim the opposite, must be in English and no longer than four sentences. Because of the spread the request is executed ten times, and the case passes if nine or more answers meet the criteria. The threshold is agreed with the team by risk: for amounts of money it is stricter than for the tone of a greeting. Property checks are done with ordinary asserts (a string is contained, language, length) and semantically when a criterion is hard to write as a rule (automation is covered in separate lessons of the chapter).
Limits and alternatives. A set of a few requests gives only an impression, not a guarantee: the wider the feature, the bigger the set needed, and it must contain ordinary, boundary (an empty or very long request, another language) and hostile requests. The set has to be maintained: new production bugs are added to it as cases. A test that runs against a real model is slow and costs money, so some checks are done on mocks or recorded answers, and the full evaluation runs on a schedule or before a release. Lowering the temperature in the test environment reduces the spread, but the final evaluation should use settings close to production. Manual exploratory testing stays necessary: people quickly find odd behaviour the set did not foresee.
Common mistakes.
- Comparing text with a reference: the test is unstable and the team switches it off.
- A single run instead of a series: a lucky answer masks instability.
- Checking only typical (happy-path) requests and not checking the refusal for the unknown, off-topic or hostile instruction.
- Not tying criteria to the knowledge base: an answer that "looks right" is not an answer right by the data.
- Not re-running the set after a prompt or model change: LLM feature regressions come from exactly such changes.
Check yourself
After a model update the bot's answers became more stylish while the set of criteria is still green. Does that mean nothing changed?
Answer
No. The set checks only the properties built into it. Tone, length and behaviour on new kinds of requests may have changed. So after a model change you compare metrics on the whole set and add a human review of a sample of answers, and you extend the set with cases for the changes found.
Why is it better to run the fee case ten times and count the share than to run it once?
Answer
Because the answer is probabilistic: one run can be luckily good or unluckily bad. A series shows stability: the share of answers that passed the criteria. A threshold separates a rare spread from a real problem.