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 with a prompt.
- Read and write unit tests with assertions and a test runner such as pytest.
- Use Git and a CI system such as GitHub Actions.
You do not need prior experience with evaluation tools. This chapter builds the working model for why LLM features break without warning. The later chapters in this tutorial cover the tooling in detail.
What a regression means for an LLM feature
A regression is a change that makes a previously working behavior worse. In conventional software, a regression usually shows up as a failing test, an exception, or a crash. The code path that used to return 42 now returns 41, and an assertion catches it.
LLM features behave differently. When a prompt edit or a model upgrade makes the output worse, nothing throws an error. The API call still returns HTTP 200. The text still parses as a string. The feature still "works" in the sense that it produces output. The output is just less correct, less well formatted, less safe, or less useful than before.
This is why regressions in LLM features are called silent. No component reports a failure. A person has to notice the quality drop, and that often happens days or weeks later, after real users have been affected.
Here is a concrete example. Suppose a support tool asks a model to classify tickets and return JSON:
SYSTEM_PROMPT = """You are a support triage assistant.
Classify the ticket and reply with JSON containing the keys
"category" and "priority". Categories: billing, bug, feature, other.
Priorities: low, medium, high."""A teammate edits the prompt to make replies friendlier. The model now answers with a sentence before the JSON: Sure! Here is the classification: {"category": "bug", ...}. Your code calls json.loads on the reply and fails in production for a fraction of requests. In a different version of the same story, the JSON stays valid but the model begins labelling most billing complaints as other. No code fails at all. Only the numbers on a dashboard shift, and only if someone is looking at them.
Why LLM behavior is hard to pin down
Several properties of LLM systems combine to produce silent failures.
The output space is open-ended
A function that adds two integers has one correct answer. A prompt that summarizes a document has thousands of acceptable answers and many more unacceptable ones. You cannot write assert output == expected for most tasks, so the usual test pattern does not apply directly. You need checks that describe properties of a good answer instead of one exact answer.
Behavior depends on text you wrote informally
A prompt is a program written in natural language. Small wording changes can shift behavior in ways that are hard to predict. Reordering two instructions, adding an example, or changing "must" to "should" can alter how often the model follows a rule. There is no compiler or type checker to flag the effect of the change.
Fixes in one place break another
A prompt usually handles many kinds of input. Tuning it to fix one failing case often shifts behavior on other cases. Without a fixed set of cases to re-run, you only see the case you were looking at. This is the same pattern as an overfitted model: the change helps the example in front of you and hurts the rest.
Output varies from run to run
Most LLM APIs sample tokens with some randomness. The same prompt can give different outputs on consecutive calls, even at low temperature. This has two consequences for testing:
- A single passing run does not show that a prompt is correct.
- A single failing run does not show that a prompt got worse.
Chapter 5 covers how to handle this with repeated runs and tolerances. For now, keep in mind that a regression in an LLM feature is a statement about a rate (for example, "valid JSON in 98% of runs, down from 99.5%"), not about one output.
The model is a dependency you do not control
If you call a hosted model, the provider can update, retire, or reroute the model behind a name. Aliases such as latest or an unversioned model name may point to a new snapshot without any change in your repository. Even with pinned versions, providers may change infrastructure, safety filters, or default parameters. Your code did not change, but your results did.
The ways a regression gets in
It helps to list the places where a change can enter your system. The next chapter treats these in more detail. This list is enough to see why a normal test suite misses them.
| Change | Example | Why it goes unnoticed |
|---|---|---|
| Prompt edit | Rewording instructions, adding an example | Code still runs, output still looks plausible |
| Model version change | Switching from one snapshot to the next, or an alias moving | No code diff at all for an alias move |
| Parameter change | Different temperature, max tokens, or stop sequence | Output is usually fine, but edge cases degrade |
| Context change | A retrieval index update, a longer chat history, new tool output | The prompt text is identical, the input to the model is not |
| Downstream code change | A new output parser or post-processing step | The model output is fine, the interpretation is not |
Notice that only some of these appear in a pull request diff. A moving model alias and a changed retrieval index produce no diff in the files a reviewer reads. That is the strongest argument for running evaluations automatically and on a schedule, not only when someone edits a prompt file.
Why conventional tests are not enough
Unit tests for LLM features do exist, and they are useful for the deterministic parts: prompt template rendering, output parsing, and retry logic. You should keep writing them. They do not cover the model's behavior.
A common mistake is to mock the model in all tests. A mock returns the output you wrote, so the test checks your parser and nothing about the prompt. When the prompt regresses, the mocked tests still pass.
Another mistake is to test against a single hand-picked example. That test passes when the prompt works for that example and says almost nothing about the other inputs your users send.
The table below compares the two approaches.
| Property | Conventional unit test | LLM regression test |
|---|---|---|
| Input | One value per test | A dataset of many cases |
| Expected result | An exact value | A set of properties: format, content, constraints |
| Result of one run | Pass or fail is definitive | Pass or fail is one sample |
| Suite result | Every test must pass | A pass rate compared with a baseline |
| Trigger | Code change | Code change, prompt change, model change, and a schedule |
| Cost | Negligible | API calls cost money and take time |
The last row matters. Because each case calls a paid API, you have to decide how many cases to run and how often. Chapter 9 covers test tiers for this reason.
The shape of a solution
The fix is to treat prompts and model choices like code that needs a test suite, adapted to the properties above. The tutorial builds this up in stages:
- A golden dataset. A versioned set of representative and adversarial inputs, each with the properties a good answer must have.
- Checks. Deterministic assertions for format, content, and constraints. Where those cannot express quality, a judge model scores the output against a rubric, and you validate the judge against human labels.
- Aggregation. Repeated runs and a pass rate, compared with a stored baseline within a tolerance.
- Automation. A CI workflow that runs a fast suite on every pull request and a fuller suite on a schedule.
- Maintenance. Reporting that helps you triage failures, and a deliberate process for updating datasets and baselines.
The diagram shows how these parts connect and where a regression is caught.
A minimal regression test
Here is the smallest useful version of the idea, using the ticket classifier from earlier. It does not yet have a dataset file, repeated runs, or a baseline. Those come in later chapters. It does show the key shift: the test checks properties of the output over several inputs, and it calls the real model.
The example assumes a function run_prompt that sends a ticket to your model and returns the raw text reply. The stub below stands in for it so that the file runs as shown. Replace the stub with your own model call.
import json
import pytest
ALLOWED_CATEGORIES = {"billing", "bug", "feature", "other"}
ALLOWED_PRIORITIES = {"low", "medium", "high"}
TICKETS = [
("t1", "I was charged twice for my subscription this month."),
("t2", "The export button crashes the app every time I click it."),
("t3", "It would be great to have a dark mode."),
]
def run_prompt(ticket_text: str) -> str:
# Stub so this file runs as shown. Replace with a real model call.
return json.dumps({"category": "other", "priority": "low"})
@pytest.mark.parametrize("ticket_id, text", TICKETS, ids=[t[0] for t in TICKETS])
def test_reply_is_valid_classification(ticket_id, text):
output = run_prompt(text)
data = json.loads(output) # fails if the model adds prose around the JSON
assert data["category"] in ALLOWED_CATEGORIES
assert data["priority"] in ALLOWED_PRIORITIESWith a real model behind run_prompt, this test would have caught the "Sure! Here is the classification" regression from the opening example, because json.loads raises on the extra prose. It would not catch the second regression, where billing tickets drift to other, because the output is still valid. To catch that, the dataset needs an expected category for each ticket, which is the subject of Chapter 3.
Run it with:
pytest -qThe stub always returns other, so the test passes. That is itself a lesson. A test that checks only that the reply is well formed will pass for a model that gives the wrong answer every time. Format checks are a floor, not a measure of quality.
Failure modes to expect
These are the patterns you will see most often when a team first meets silent regressions.
- The alias move. A team uses a model name without a version. The provider updates what the name points to. Outputs change on a Tuesday with no commit to explain it.
- The one-case fix. A developer fixes a reported bad output by adding a rule to the prompt. The rule changes behavior on a category of input nobody retested.
- The mocked pipeline. All tests mock the model. The suite is green while the prompt is broken.
- The vibe check. A developer tries three inputs by hand, sees good answers, and merges. Three inputs cannot represent the real input distribution, especially the rare and adversarial inputs.
- The averaged-away failure. Overall quality looks stable, but one important category (for example, safety refusals) got worse while others improved. Aggregate numbers hide it. Later chapters cover per-category reporting.
- The flaky threshold. A test demands 100% of runs pass, fails randomly because of sampling variance, and the team learns to ignore or disable it.
The last one is worth dwelling on. A test suite people stop trusting is worse than no suite, because it gives false confidence. Much of the design work in later chapters, such as repeated runs, tolerances, and baselines, exists to keep the suite trustworthy under randomness.
What to carry forward
- A regression in an LLM feature is a measurable drop in quality, and it usually raises no error.
- Causes include prompt edits, model version changes, parameter changes, context changes, and downstream code changes. Only some of them show up in a code diff.
- Outputs are open-ended and vary between runs, so tests check properties over many cases and judge results as rates.
- Mocked tests and single-example tests do not detect prompt or model regressions.
- The solution is a versioned dataset, layered checks, a baseline with a tolerance, and automated runs in CI.
Exercise
A teammate says: "Our LLM tests are all green and we mock the model call, so a prompt change can't break anything." Give two reasons this claim is wrong, and name one kind of regression that a JSON-validity check alone would still miss.
Show answer
First, a mocked model returns output you wrote, so the tests exercise your parser and code, never the prompt or the model. A prompt edit cannot make them fail. Second, regressions also come from changes outside your code, such as a model alias moving to a new snapshot, a changed parameter, or different retrieved context, and mocks hide all of these. A JSON-validity check would still miss content regressions, for example a classifier that returns valid JSON but labels billing tickets as "other", or a summary that is well formed but leaves out key facts.
Exercise
Why is "this prompt change fixed the failing example" not enough evidence to merge it? What would you need instead?
Show answer
The prompt handles many inputs, and a change that fixes one case can shift behavior on others. Output also varies between runs, so one passing run is a single sample. You need a fixed set of representative and adversarial cases, run through the changed prompt, with a pass rate compared against the previous baseline within a tolerance.