Test oracles for AI systems
Why This Matters
A test needs an expected result: the test oracle. For a tax calculation, the oracle is the tax table. For a model that predicts which patients will develop complications, or writes a summary of a meeting, there is often no table, no specification and no single right answer. The test oracle problem is the central difficulty of testing AI, and every technique in the rest of this course is, in part, an answer to it.
What you will learn
- Why test oracles are hard for AI-based systems
- Five ways to deal with the oracle problem
- How to choose an oracle for a given scenario
Syllabus: AI-4.1.3.
Why the oracle is hard
The syllabus names five causes:
- Probabilistic outputs. The system is right most of the time, by design. A single wrong answer is not necessarily a failure, so “expected = actual” does not work.
- Exploratory development with incomplete specifications. Data scientists experiment until the results look good. What the system should do is often not written down; it is implied by the training data.
- Complex tasks. Is this X-ray abnormal? Will this customer churn? If people could easily say what the right answer is, you might not need the model.
- Subjective correctness. Is this summary good? Is this image beautiful? Is this answer polite enough? Different experts give different answers.
- Self-learning systems. What is “correct” changes as the system adapts (lesson 25). Yesterday’s expected result may be wrong today.
Five ways to deal with it
1. Output boundaries
You may not know the exact output, but you know the range, tolerance or limit it must stay within. An autonomous car must stop within a maximum distance. A predicted house price must be positive and below ten times the area average. A probability must be between 0 and 1. The dosing model in lesson 7 may never propose more than a maximum per kilogram. These checks do not prove the output is right, but they catch outputs that are certainly wrong.
2. Environmental boundaries
Fix the conditions under which you test, so results can be compared: the lighting, the temperature, the network latency, the camera angle. A pedestrian detector is tested under defined light levels, so that “worse in the dark” is a finding and not noise between runs.
3. Expert consultation
Ask domain experts what the right answer is: a radiologist for the X-rays, a fraud analyst for flagged transactions. Their judgement is often the best oracle available, but it is expensive, slow, and experts disagree and make mistakes. Use several experts, measure how much they agree (lesson 39), and use them for samples rather than every test.
4. Specialised testing techniques
Three techniques work without a full expected result:
- Metamorphic testing (lesson 46): you don’t know the right output, but you know how it must change when the input changes.
- Back-to-back testing (lesson 49): compare with another implementation of the same function, a pseudo-oracle. Differences point to defects in one of them.
- A/B testing (lesson 49): compare two variants statistically on the same inputs; the current version acts as a partial oracle for the new one.
5. Proxy oracles
Use another system or model as the judge: a proxy model trained on labelled data, a conventional rule-based checker, or a second AI that evaluates the first (the “LLM as a judge” of lesson 28). Proxies scale where experts do not, but they have their own errors, and a proxy built the same way as the system under test may share its blind spots.
Choosing an oracle
| If… | Consider… |
|---|---|
| You can say what is certainly wrong | Output boundaries |
| Results depend on conditions | Environmental boundaries |
| Correctness needs expertise or taste | Expert consultation, on a sample |
| You know how outputs relate to each other | Metamorphic testing |
| Another implementation exists | Back-to-back testing |
| You are replacing a version in use | A/B testing |
| You need to judge many outputs cheaply | A proxy oracle, checked against experts |
In practice you combine them: boundaries catch the absurd, metamorphic and back-to-back tests catch inconsistencies, experts calibrate the rest.
Exercise
Choose one or more oracles for each scenario, and explain why.
- A model predicts the delivery time of parcels in days.
- An LLM writes summaries of customer complaints for the support team.
- A new version of a credit-scoring model replaces the current one.
- A model detects tumours on scans.
- A self-learning thermostat learns the household’s schedule.
Show suggested answer
- Output boundaries (between 1 and 30 days, never before the order date), metamorphic testing (a longer distance does not give a shorter time), and comparison with actual delivery times once they are known.
- Expert consultation on a sample (support agents rate the summaries with a rubric), plus a proxy oracle: an LLM judge that checks each summary against the complaint for missing facts, calibrated against the agents’ ratings. Output boundaries help too: a maximum length, no names that are not in the complaint.
- Back-to-back testing against the current version on the regression set (where do they differ, and who is right?), then A/B testing on live traffic with agreed metrics.
- Expert consultation: several radiologists, with measured agreement, as the reference labels. Environmental boundaries: scanner type, resolution and contrast fixed per test. Metamorphic tests for robustness (a slight rotation does not change the result).
- Environmental boundaries with simulated schedules (lesson 25), output boundaries (never below 12 °C or above 25 °C), and comparing behaviour after adaptation with the simulated household’s real schedule.
Exam-style questions
1. Which is a reason why test oracles are difficult for AI-based systems?
- A. AI-based systems produce no output
- B. Correctness can be subjective, for example the quality of a generated text
- C. AI-based systems always have complete specifications
- D. AI-based systems are deterministic
Show answer
2. A tester checks that an autonomous vehicle always stops within 12 metres at 30 km/h, without knowing the exact stopping distance. Which oracle approach is this?
- A. Expert consultation
- B. Output boundaries
- C. Proxy oracle
- D. Back-to-back testing
Show answer
3. What is a risk of using experts as a test oracle?
- A. Experts are always correct
- B. Experts may disagree and can be wrong
- C. Experts can only judge numerical outputs
- D. Experts cannot be used for AI systems