How to evaluate an AI application before launch: test sets, metrics and hallucination checks
An AI assistant that gives five good answers in a demo can still fail on the sixth question in production. Language models are not deterministic, and small changes to a prompt, a document or a model version can change behaviour in unexpected places. The remedy is the same as in conventional software: tests. This article describes an evaluation approach that small teams can implement.
Define what "good" means
Before testing, the success criteria must be explicit. Typical criteria for a business assistant:
- Correct: the answer matches the facts in the source documents.
- Grounded: every statement is supported by the retrieved sources; nothing is invented.
- Complete: the question is fully answered.
- Appropriately cautious: the assistant says that it does not know when the sources do not contain the answer, and hands over to a person where intended.
- In scope and in tone: no answers outside the intended subject area; the company's style is kept.
- Safe: no disclosure of other people's data, and no compliance with instructions hidden in documents or user messages.
For extraction tasks the criteria are simpler: the right value in the right field.
Build a test set
A test set is a list of inputs with the expected result or with the criteria a good answer must meet. Good sources are:
- real questions from emails, tickets and chat logs (anonymised);
- the 30 to 50 most frequent requests;
- known difficult cases: ambiguous questions, outdated information, similar product names;
- questions that must not be answered, because the information is not in the sources or the topic is out of scope;
- adversarial inputs: attempts to override the instructions or to obtain other customers' data.
Fifty well-chosen cases are worth more than a thousand random ones. The set grows over time: every error found in production becomes a new test case.
Three ways to grade
1. Code-based checks. Fast, cheap and exact wherever the expected result is unambiguous: does the extracted amount equal the expected one, is the output valid JSON, does the answer contain the required link, was the correct tool called? Use this method wherever possible.
2. Model-based grading. A second model call assesses the answer against a rubric, for example "Is every claim in the answer supported by the provided sources? Answer yes or no and name unsupported claims." This scales well for free-text answers. Two precautions are necessary: the rubric must be specific, and the grader itself must be validated against human judgements on a sample, because it can be wrong too.
3. Human review. Domain experts assess a sample. This is the reference standard and is needed to calibrate the first two methods, but it is too slow to be the only method.
In practice all three are combined: code checks for everything measurable, model grading for free text, and a regular human sample.
Evaluate retrieval separately
In systems that answer from company documents (retrieval-augmented generation), there are two possible sources of error: the search did not find the right passage, or the model answered badly despite having it. They need different fixes, so they should be measured separately:
- Retrieval: for each test question, is the passage that contains the answer among the retrieved passages?
- Generation: given the right passages, is the answer correct and grounded?
If retrieval is the weak point, improving the prompt will not help; the work lies in document preparation, chunking and search. The architecture is described in How to build an AI assistant for your business.
Checking for hallucinations
"Hallucination" describes statements that sound plausible but are unsupported. Measures that reduce and detect them:
- instruct the model to answer only from the provided sources and to say so when they do not contain the answer;
- require citations: each statement refers to a source passage, and the application checks that the cited passage exists;
- run a groundedness check (model-based) on answers before they are sent, at least for high-risk topics;
- copy critical values such as prices, dates and legal wording verbatim from the source instead of paraphrasing;
- include unanswerable questions in the test set and measure how often the assistant correctly declines.
The rate will not be zero. The decision that follows is a business one: for which topics is the remaining risk acceptable, and where is human review required?
Metrics that matter to the business
Technical quality figures should be complemented by figures that describe the result:
- resolution rate without human intervention;
- hand-over rate and reasons;
- error escape rate (wrong answers that reached customers);
- cost and response time per request;
- user feedback.
After launch: regression testing and monitoring
- Run the test set before every change to prompts, documents, tools or the model version, and compare with the previous result. Model versions are retired by providers on a schedule, so a change of model will come.
- Sample production conversations regularly and have them reviewed.
- Track signals such as negative feedback, repeated questions and hand-overs.
- Keep versions of prompts and configuration so that a regression can be traced and rolled back.
How much is enough?
The effort should match the risk. An internal assistant for meeting notes needs a small test set and occasional sampling. An assistant that answers customers about prices and contracts, or an automation that triggers payments, needs a thorough test set, hard checks in code and human approval for critical actions. Frameworks such as the NIST AI Risk Management Framework provide a structure for this kind of risk-based approach.
Conclusion
Evaluation turns "it seems to work" into a number that can be tracked. A test set is the most valuable asset of an AI project: it makes model changes safe, improvements measurable and discussions short.
uurstudios delivers AI applications with a test set, automated checks and an agreed quality bar. Requirements can be shared through the contact form.