How AI works · beginner · About 8 minutes
The AI test that passes on Monday and fails on Tuesday
A test of an AI feature fails about 1 run in 6, and since a model upgrade it fails most runs. Nothing in the code changed. Find out why, and write a test that means something.
You maintain an app that uses a language model to sort refund requests.
What happened
Your app sends each refund request to a language model, which decides whether to approve it. A test checks one clear case: a parcel that never arrived must be approved.
The test has always failed now and then, and people re-ran it until it passed. Last week the team moved to a newer model. Now it fails on most runs, and nobody trusts the test suite.
The incident is made up. How things work in it is real, with sources at the end.
The evidence
Everything you need is here. Read it before you decide.
def test_lost_parcel_is_approved():
reply = ask_model(
"Customer says the parcel never arrived. Tracking shows no delivery. "
"Should the refund be approved? Answer with the decision."
)
assert reply == "Refund approved."- Mon 09:12PASSRefund approved.
- Tue 10:40FAILApproved. The parcel was never delivered.
- Tue 10:44FAILRefund approved: tracking confirms no delivery.
- Tue 11:02FAILYes, approve the refund.
"Removed temperature=0 from ask_model. The new model returns an error 400 when temperature is set."
Your decisions
Decision 1 of 2
Decision 1
Why does the test fail when the code did not change?
Decision 2
How should the test work?
What went wrong
A language model writes an answer one tokenTokenThe small piece of text a language model reads and writes, often part of a word. Prices, limits and the context window are all counted in tokens. at a time, choosing each from a list of likely next tokens with some randomness. TemperatureTemperatureA setting that controls how much chance goes into each word a model picks. Low gives focused, predictable answers; high gives more varied ones. sets how much. Lower values give more predictable output, but even at 0 the results are not fully the same every time. So a test that compares the model's exact words is testing a dice roll.
The setting is also going away. Claude Opus 4.7 and 4.8 and Claude Sonnet 5 return an error for a non-default temperature, Claude Haiku 5.5 can too, and the Gemini API deprecated it in July 2026. Code that relied on temperature 0 for steady output loses that crutch when it upgrades, which is what happened here.
The fix is to test what the app depends on. Here that is a decision, not a sentence. Ask for it in a fixed format and test the format's value. Then run each case a few times, because one pass says little about something that varies.
Keep these
- The same prompt can give different words on every run. Design tests for that.
- Test the decision or the data your app uses, never the exact phrasing.
- Do not lean on temperature 0. Several current models no longer accept it.
The ideas behind it
LessonHow AI writes its answers: one piece at a timeSources
Where each fact comes from
This page was last checked against these sources on 14 October 2026.
- 1Glossary
Anthropic, Claude API documentation · 14 October 2026
Temperature controls how random the model's predictions are. Higher values give more varied output and lower values give more predictable output. Even with temperature set to 0 the results are not fully the same every time.
- 2Claude Platform release notes
Anthropic · 14 October 2026
Setting temperature, top_p or top_k to a non-default value returns a 400 error on Claude Opus 4.8, as on Opus 4.7, and Claude Sonnet 5 and Claude Haiku 5.5 return 400 for non-default temperature too.
- 3Gemini API release notes
Google · 14 October 2026
On 21 July 2026 the sampling parameters temperature, top_p and top_k were deprecated in the Gemini API.
- 4Generation strategies
Hugging Face, Transformers documentation · 14 October 2026
Sampling picks a token at random according to the model's probabilities, so every token with a chance above zero can be chosen.