Sub topic 1
Why prompts and models regress silently
Prerequisites
This chapter assumes you can do the following:
- Write basic Python and call an LLM API.
- Write prompts and read model output.
- Use a unit test runner such as pytest, including assertions.
- Use Git and a CI system such as GitHub Actions.
You do not need any evaluation tooling yet. Later chapters build it step by step.
What "silent" means here
In a conventional program, a broken change usually fails loudly. A type error, a crashed process, or a failed assertion tells you something is wrong.
An LLM feature fails differently. The call succeeds, the response arrives, and the HTTP status is 200. The text may still be worse than yesterday. It may be longer, miss a required field, drop a safety caveat, or answer in a different tone. No exception is raised, so nothing alerts you.
A regression is a case where a change makes the feature worse at something it used to do well. Regressions are silent when nothing in your pipeline measures that behavior.
Why unit tests are not enough
Conventional unit tests assume the same input always gives the same output. Two properties of LLM features break that assumption.
- Output is variable. Even at a low temperature (the setting that controls randomness), the same prompt can return different wording on different runs.
- Correctness is fuzzy. Many valid answers exist. An exact string match fails on good answers, and a loose check passes bad ones.
So an LLM test has to check properties of the output, such as valid JSON, required keys, or required phrases. It also has to judge results across many cases, not one. A single passing example says little. A pass rate over fifty examples says much more.
How a regression slips through
Consider a support-ticket classifier. Its prompt asks for JSON with the keys category and urgency. A teammate adds one sentence to make explanations friendlier. They try three tickets by hand, and all three look fine. They merge.
Two weeks later, a downstream parser starts failing. About 8% of responses now begin with "Sure! Here is the JSON:" before the object. The prompt edit caused it, but the effect only showed up on certain inputs. Manual spot checks could not have found it.
The diagram shows the gap. Without an automated check, the change goes straight to production.
Common causes of silent regressions
| Cause | Example | Why it is hard to see |
|---|---|---|
| Prompt edit | Adding a friendliness instruction | Affects only some inputs |
| Model upgrade | Provider retires a model version | Behavior shifts on edge cases |
| Parameter change | Raising temperature from 0.2 to 0.7 | Output looks fine on average |
| Context change | A retrieval index returns different documents | The prompt text did not change |
Chapter 2 covers these change surfaces in detail. For now, note that most of them are edits that code review does not treat as risky. A one-word prompt change looks harmless in a diff.
What a regression test does
A regression test for an LLM feature has three parts:
- A fixed set of inputs with known expectations, called a golden dataset.
- Checks that score each output, either by rule or by a judge model.
- A threshold that decides whether the overall result is acceptable.
CI runs these parts on every relevant change. The result is a pass or fail signal, produced before the change reaches users.
Here is the smallest useful version of idea 1 and 2 together. It checks one output for valid JSON and one required key.
import json
def check_output(output: str) -> list[str]:
"""Return a list of problems found in a model response."""
problems = []
try:
data = json.loads(output)
except json.JSONDecodeError:
return ["not valid JSON"]
if "category" not in data:
problems.append("missing key: category")
return problems
print(check_output('{"category": "billing"}'))
print(check_output('Sure! Here is the JSON: {"category": "billing"}'))The first call prints []. The second prints ['not valid JSON'], which is exactly the failure from the classifier story.
Summary of the idea
LLM regressions are silent because the call succeeds while quality drops. They are hard to catch by hand because output varies and failures concentrate on specific inputs. The fix is to treat prompts and model settings like code: keep a versioned set of cases, score outputs automatically, and gate changes in CI.
Exercise
A teammate changes one sentence in a prompt and checks five examples by hand. All look good. Give two reasons this does not show the change is safe, and name what you would add.
Show answer
Five examples are too few to represent real inputs, and failures may appear only on specific inputs, such as the 8% of responses with extra text. Output also varies between runs, so one good run does not guarantee the next. Add a golden dataset with automated checks, such as valid JSON and required keys, and run it in CI against a pass-rate threshold.
Exercise
Why does a 200 status code from the model API say nothing about whether the feature still works?
Show answer
The status code only reports that the request completed. It does not describe the quality, format, or correctness of the generated text, so a degraded response still returns 200.