Skip to main content

How to test generative AI

Why This Matters

A classifier answers with one of a few labels; you can count how often it is right. A generative AI system answers with a paragraph, an image or a piece of code that has never existed before. There are endless possible inputs, endless acceptable outputs, and the same prompt gives a different answer each time. Testing it needs a different toolkit: criteria instead of expected results, a judge instead of an assertion, and a clear grip on everything that counts as input.

What you will learn

  • What to evaluate in GenAI output, beyond correctness
  • The input explosion problem: everything that influences a GenAI system’s output
  • How outputs are judged (people, an LLM as judge), and what benchmarks are for
  • The non-functional side: resources and response times

Syllabus: AI-4.2.1.

What to evaluate

The syllabus lists five qualities of generated output, on top of the usual functional and non-functional requirements:

  • Correctness: are the facts right? Does the code run? Does the answer match the source documents?
  • Coherence: is it consistent and logical from start to end? Does it contradict itself?
  • Creativity: for creative tasks, is it inventive rather than formulaic?
  • Originality: is it not copied from training data or existing work?
  • Novelty: does it bring something new, rather than repeating the prompt back?

Which ones matter depends on the use. A support chatbot needs correctness and coherence, and creativity is a risk. A marketing copy tool needs creativity and originality, and invented product facts are still a defect.

Black-box testing

Most GenAI testing is black-box: feed the system varied prompts, images or partial data, and assess the outputs for clarity, originality and adherence to the rules of the domain. It works for chatbots and for design tools alike. Vary:

  • the content: typical requests, edge cases, out-of-scope requests, ambiguous ones
  • the form: short and long, polite and rude, with typos, in other languages
  • the context: a fresh conversation, a long one, a follow-up question that relies on earlier answers

And repeat every test: one good answer proves little (lesson 26).

The input explosion problem

In a conventional system the input is what the user types. In a GenAI system, many things shape the output:

InputExample
System prompt“You are the support assistant of TechCorp. Answer only about our products.”
User prompt“How much does Widget Pro cost?”
API access and toolsWhich tools, documents or APIs the model may use
ParametersTemperature, maximum number of tokens, top-p
Context windowEverything earlier in the conversation, retrieved documents (RAG, lesson 14)

Each combination can behave differently. A test result is only reproducible if all of these are recorded, and a change to any of them (a reworded system prompt, a new model version, a higher temperature) can change behaviour that was tested. Treat the system prompt and the parameters as configuration under version control, and rerun the regression set when they change.

Judging the output

There is rarely an exact expected output, so someone or something has to judge.

  • Manual review against qualitative criteria: a rubric (is it correct, complete, polite, within scope?) applied by testers or domain experts. Reliable but slow and expensive.
  • A second GenAI system as the judge (“LLM as a judge”): another model scores each output against the rubric. Fast and scalable, so it can judge thousands of outputs on every release. But the judge may repeat the same biases or errors as the system it judges, especially if it is a similar model. Calibrate it: have people judge a sample too, and check how often the judge agrees with them.
  • Automatic checks for what can be checked mechanically: the answer contains the right price; it does not contain words from the system prompt; generated code compiles and passes its tests; the output is valid JSON.

A practical setup combines all three: automatic checks on everything, an LLM judge on everything, people on a sample and on whatever the judge flags.

Non-functional testing

GenAI models are large, and resource use is part of quality: CPU, GPU, memory and bandwidth, during training and during inference, and the response time the user experiences. A chatbot that takes 20 seconds to answer, or a feature that costs more in compute than it earns, fails just as surely as one that gives wrong answers. Measure time to the first token, total response time, and cost per request under realistic load.

Benchmarks

A benchmark is a standardised dataset with tasks and a scoring method, so models can be compared consistently and reproducibly: benchmarks for language understanding, reasoning, coding, maths, safety. They are useful to choose between models and to detect regressions between versions.

Their limits for testers: a benchmark measures what it measures, not your use case. A model that scores well on a general reasoning benchmark can still invent your product prices. And popular benchmarks may have leaked into training data, which inflates scores. Use benchmarks to shortlist models; use your own test set, built from your own use cases, to accept them.

Exercise

Test the AI Chatbot Testing lab for ordinary use, not attacks (that is the next-but-one lesson, red teaming). Use this checklist, and for each item write one prompt, run it at least three times, and record pass or fail with the evidence.

#CheckCriterion
1CorrectnessProduct prices match the knowledge base: Basic $49.99, Pro $99.99, Enterprise $299.99
2ConsistencyThe same question gives the same facts every time
3GroundingQuestions outside the knowledge base get “I don’t know”, not an invented answer
4CoherenceA follow-up question that refers to the previous answer is understood
5ScopeA question outside the domain (health, legal) is declined politely
6ToneAn unhappy customer gets a polite, non-judgemental answer
Show what a session finds
  1. Pass for the product overview (“What products do you offer?” lists all three with correct prices).
  2. Fail: “What is the price of Widget Pro?” sometimes gives $99.99 one-time and sometimes $89.99 per month with a yearly plan. Found only by repeating the question.
  3. Fail: “Who is your CEO?” gets an invented name, career and degree. (Note: “When was the company founded?” gets a polite general reply. Different wordings of the same kind of question behave differently.)
  4. Fail: after a few messages, “What did I ask earlier?” gets “each conversation starts fresh”.
  5. Fail: a question about a headache gets specific medication advice, including a dose change.
  6. Fail: an angry message gets a reply that blames customers for not reading the manual.

Five of six checks fail. The lab is built to fail, but the pattern is realistic: the first check (the happy path) passes, and everything around it does not. Notice that 2 would pass if you asked once, and 3 depends on the wording. That is why GenAI tests need repetition and variation.

Exam-style questions

Quiz

1. What is meant by the input explosion problem in testing generative AI?

  • A. The model receives too many requests
  • B. System prompts, user prompts, API access, parameters such as temperature, and the context window all influence the output, creating a very large input space
  • C. The training data is too large to test
  • D. Users enter very long prompts
Show answer
B.
Quiz

2. A team uses a second LLM to judge the answers of its chatbot. What is a risk of this approach?

  • A. The judge cannot process text
  • B. The judge may repeat the same biases or errors as the system it judges
  • C. The judge is slower than manual review
  • D. The judge only works for image generation
Show answer
B. Calibrate the judge against human reviews.
Quiz

3. What is the main purpose of benchmarks for generative AI?

  • A. Replacing all other testing
  • B. Comparing models consistently and reproducibly on standardised tasks
  • C. Generating training data
  • D. Measuring the energy use of a data centre
Show answer
B.