Back to insights

How to Test AI Features That Never Give the Same Answer Twice

LFT Industries

A normal test says: given this input, expect exactly this output. AI features break that contract. Ask a language model the same question twice and you may get two different, equally correct answers. Change one sentence in a prompt and quality can improve on ten cases while quietly breaking three others. Without a way to measure that, every change to an AI feature is a guess.

Evals: tests that score instead of match

The answer is an evaluation suite, usually shortened to "evals". An eval is a collection of realistic inputs, each paired with a way of deciding whether the output is good enough. Run the whole set, get a score, and compare it against the previous version. The goal is not a perfect score; it is knowing, before release, whether a change made things better or worse.

Three kinds of checks

  • Deterministic checks. Anything code can verify should be verified by code. Is the output valid JSON? Does it include the required fields? Is the extracted date a real date? Did the assistant call the booking tool exactly once? These checks are fast, free and never flaky.
  • Reference comparisons. For tasks with a known answer (classification, extraction, routing), compare against the expected label or value. Track accuracy per category so a drop in one area is not hidden by gains elsewhere.
  • Model-graded checks. For qualities only a reader can judge (was the reply polite, did it answer the question, did it stay within the facts provided), a second model can grade against a short, specific rubric. Keep the rubric narrow: "Does the answer contain any claim not supported by the context? yes/no" grades far more reliably than "rate this answer from 1 to 10".

Build the test set from reality

The most valuable cases are not invented; they are collected:

  • Real user inputs (anonymised), especially the ambiguous, misspelled and multilingual ones.
  • Every production failure, added the day it is found, so it can never silently return.
  • Edge cases the business cares about most: refunds, complaints, anything with legal or safety weight.
  • Adversarial inputs: attempts to make the assistant ignore its instructions or reveal data.

Test the system, not just the prompt

An AI feature is more than a prompt. Retrieval, tool calls, and the code that post-processes the output all affect what the user sees. Good evals run the real pipeline with external services replaced by recorded responses, so a test of "book a table for Friday" exercises the actual tool-calling path without touching a live calendar.

Make it part of the release process

  • Run evals in CI on every change to prompts, models, retrieval settings or tool definitions.
  • Set thresholds per category. A release that drops safety-related cases below their bar is blocked, even if the overall score went up.
  • Re-run when the provider changes the model. Hosted models are updated over time; pin versions where possible and re-evaluate before switching.
  • Keep watching in production. Sample live conversations, grade them with the same rubrics, and feed failures back into the test set.

The payoff

Teams with a solid eval suite move faster, not slower. They can try a cheaper model, rewrite a prompt or change retrieval settings and know within minutes whether the change is safe. Teams without one either freeze their AI features for fear of breaking them, or ship changes and find out from users. The suite is a small investment compared with either outcome.

FAQ

Common questions

What is an eval in AI development?
An eval is a repeatable test for an AI feature: a set of realistic inputs, each with a way of judging whether the output is acceptable. Unlike a unit test it scores quality across many cases, so you can compare one version of a prompt or model against another.
Can one AI model be used to grade another?
Yes, and it is common for judging qualities such as tone or relevance that code cannot check. It works best with a narrow rubric and when its judgements are periodically compared with human ratings to make sure the grader itself is reliable.
How many test cases does an AI feature need?
Enough to cover the real variety of inputs, including the awkward ones. A few dozen carefully chosen cases catch most regressions early; the set should grow every time a real failure is found in production.

Working on something in this space?

Bring the problem: we will map it to the right engineering path.

Start a Project