Skip to content

Module 08 · Lesson 8.5

Regression Testing and Model/Prompt Changes

40 minUpdated 18 Nov 2026Part of Testing and Evaluation · AI Agent Development
On this page
  1. What you will learn
  2. What a regression is and why agents regress
  3. Compare two versions on the same cases
  4. Compare v1 and v2 with a short Python script
  5. Write a release rule before you see the results
  6. Flaky cases: repeat runs before you decide
  7. Version every prompt and model setting
  8. Conclusion and your next step
  9. Common errors and fixes
  10. Validation checklist
  11. Hands-on exercise
  12. Knowledge check
  13. Frequently asked questions
  14. References

You fix the squeaky door in your house. The next morning the window will not close. Nobody meant to break it, but the repair touched something else. Software people call this a regression: something that used to work and now does not.

Agents are full of this risk. Changing one sentence in the instructions, or switching to a newer model, can fix one answer and spoil another. This lesson shows you how to compare two versions on the same cases, how to read the difference case by case, and how to write a release rule that stops bad changes before customers see them.

What you will learn

  • Explain what a regression is and why prompt and model changes cause them.
  • Compare two versions on the same dataset and sort each case as fixed, broken or unchanged.
  • Write a release rule that protects the cases that must always pass.
  • Version every prompt and model setting so any result can be traced to its cause.

Before you start

What a regression is and why agents regress

A regression test checks that things which worked before still work after a change. For ordinary code, the change is usually a code edit. For an agent, many more things can change the behaviour without a single line of code changing.

  • The instructions. A new rule such as "keep replies short" can make the agent drop a fact it used to include.
  • A tool description or schema. A clearer description can change which tool the model picks.
  • The model. A new model version, or a different model, behaves differently even with the same prompt.
  • The knowledge base. A new or edited help page changes what the agent finds.
  • Settings. Changes such as the number of retrieved passages or the step limit shift the results.

A model provider may also update a model behind the same name. Check the provider's documentation about how model versions are named and retired. When you can, pin a specific version, so your results stay comparable.

Compare two versions on the same cases

A fair comparison changes one thing and keeps everything else equal. Run version 1 (the current agent) and version 2 (the changed agent) on the identical dataset. Save each run as a results file with a version label, using the result-line format from the module.

A regression run
  1. Freeze the dataset

    Same cases for both versions

  2. Run v1

    results for the current agent

  3. Run v2

    results for the changed agent

  4. Compare per case

    Fixed, broken, unchanged

  5. Apply the release rule

    Ship or hold back

Change one thing at a time, or you will not know which change caused the effect.

Three labels for every case

Fixed
The case failed on v1 and passes on v2. This is the improvement you were hoping for.
Broken
The case passed on v1 and fails on v2. This is the regression. Read these first.
Unchanged
The result is the same on both versions. The case may pass on both, or fail on both. Failures that stay are your to-do list.

Totals are still useful for a quick view, but the per-case table is what you read. Think of a before-and-after photo of a room. You do not only count the objects. You look at what moved.

Compare v1 and v2 with a short Python script

The script below holds six cases and the results of two versions as text. Some cases carry a must-pass tag. A case passes when the status matches and the reply contains the required words. The script sorts every case into fixed, broken or unchanged, then applies a release rule.

Pythoncompare.py
import json

CASES = """
{"id": "E01", "expect_status": "answered", "must_include": ["dispatched"], "tags": ["orders", "must-pass"]}
{"id": "E02", "expect_status": "answered", "must_include": ["delivered"], "tags": ["orders"]}
{"id": "E03", "expect_status": "needs_order_number", "must_include": [], "tags": ["orders"]}
{"id": "E04", "expect_status": "answered", "must_include": ["5-year"], "tags": ["help"]}
{"id": "E05", "expect_status": "needs_person", "must_include": [], "tags": ["out-of-scope", "must-pass"]}
{"id": "E06", "expect_status": "not_found", "must_include": [], "tags": ["adversarial", "must-pass"]}
""".strip().splitlines()

V1 = """
{"id": "E01", "status": "answered", "reply": "QF-1042 is dispatched."}
{"id": "E02", "status": "answered", "reply": "Your order is on its way."}
{"id": "E03", "status": "needs_order_number", "reply": "What is your order number?"}
{"id": "E04", "status": "needs_person", "reply": "A person will help."}
{"id": "E05", "status": "needs_person", "reply": "A person will help."}
{"id": "E06", "status": "not_found", "reply": "I cannot find that."}
""".strip().splitlines()

V2 = """
{"id": "E01", "status": "answered", "reply": "QF-1042 is dispatched."}
{"id": "E02", "status": "answered", "reply": "QF-1044 was delivered."}
{"id": "E03", "status": "needs_order_number", "reply": "What is your order number?"}
{"id": "E04", "status": "answered", "reply": "Frames have a 5-year warranty."}
{"id": "E05", "status": "answered", "reply": "Refund approved!"}
{"id": "E06", "status": "not_found", "reply": "I cannot find that."}
""".strip().splitlines()

cases = {c["id"]: c for c in map(json.loads, CASES)}

def passes(case, result):
    return result["status"] == case["expect_status"] and all(w in result["reply"] for w in case["must_include"])

def load(lines):
    return {r["id"]: passes(cases[r["id"]], r) for r in map(json.loads, lines)}

old, new = load(V1), load(V2)
groups = {"fixed": [], "broken": [], "unchanged": []}
for cid in cases:
    key = "unchanged" if old[cid] == new[cid] else ("fixed" if new[cid] else "broken")
    groups[key].append(cid)
for key, ids in groups.items():
    print(f"{key:9} {len(ids)}  {ids}")
print("v1 passes", sum(old.values()), "of", len(old), "| v2 passes", sum(new.values()), "of", len(new))
blocked = [cid for cid in groups["broken"] if "must-pass" in cases[cid]["tags"]]
print("RELEASE: NO, must-pass broken:" if blocked else "RELEASE: YES", blocked if blocked else "")

Offline and deterministic. The data is made up for the lesson. Run it with python compare.py.

What each part does

  • CASES, V1 and V2 are strings with one JSON object per line, like JSONL files. json.loads turns each line into a dictionary.
  • passes(case, result) returns True when the status is as expected and every required word is in the reply.
  • load(lines) builds a dictionary from case id to pass or fail, for one version.
  • The loop labels each case. Equal results are "unchanged". Otherwise a pass on v2 means "fixed", and a pass on v1 means "broken".
  • blocked lists the broken cases that carry the must-pass tag.
  • The last line is the release rule. Any broken must-pass case means no release, whatever the totals say.
OutputCaptured from a real run
fixed     2  ['E02', 'E04']
broken    1  ['E05']
unchanged 3  ['E01', 'E03', 'E06']
v1 passes 4 of 6 | v2 passes 5 of 6
RELEASE: NO, must-pass broken: ['E05']

Version 2 passes 5 of 6, up from 4 of 6. By the totals it looks better. But the change that made it answer more helpfully also made it approve a refund it has no right to approve (E05). The per-case view catches this and the release rule blocks it.

Write a release rule before you see the results

A release rule is a short, written condition that must be true before a new version goes live. Write it before you run the comparison. If you write it afterwards, it is easy to bend the rule to fit the result you hoped for.

RuleWhy it helps
No must-pass case may break.Protects safety rules, such as never approving a refund, and key customer promises.
Overall passes must not fall below v1.Stops a change that fixes one thing and damages many others.
Every broken case is read and explained.A broken case may be a wrong expectation, but you should decide that, not assume it.
Adversarial cases are all in the must-pass group.Attacks you have already blocked should never come back.
Start with two or three rules. Add one each time a real problem slips through.

Adversarial cases, such as the injection attempts described in Prompt Injection: What It Is and How to Defend Against It, belong in the must-pass group.

Choosing the must-pass cases

Pick cases where a failure would cost real money, break a promise or cause harm. In the Quillfeather example, these include never approving refunds, never showing staff pages and never sharing another customer's order. Keep the group small, so people take it seriously.

Flaky cases: repeat runs before you decide

A model may give a different answer to the same question on different runs. A case that passes once and fails once is flaky. If you compare single runs, a flaky case can look "fixed" or "broken" by luck.

  • Run each case several times on each version, for example five times, when it uses a real model.
  • Record how many runs passed, such as 4 of 5, and not just one pass or fail.
  • Call a case broken only if it passes clearly less often on v2 than on v1, such as 5 of 5 before and 1 of 5 after.
  • For a must-pass case, any failure in repeated runs deserves a look. A rule that holds only most of the time is not a rule.
  • Live runs cost time and money. Use scripted or recorded replies for most checks, as in Scenario-Based and End-to-End Agent Tests, and keep live repeat runs for the cases that matter.

Lowering the model's randomness setting, where the provider allows it, can reduce variation. It does not remove it, so repeat runs are still the safe habit.

Version every prompt and model setting

A regression report is only useful if you can say exactly what v1 and v2 were. Write it down. Store the instructions in a file, not buried in code, and give each change a label.

JSONversions.json
{
  "v1": {"instructions_file": "instructions_v1.txt", "model": "model-name-a", "retrieved_passages": 3, "max_rounds": 6},
  "v2": {"instructions_file": "instructions_v2.txt", "model": "model-name-a", "retrieved_passages": 3, "max_rounds": 6}
}

An example record. Check your provider's model page for real names.

  • Keep it in version control, such as Git, so every change has a date and an author's note.
  • Label every result line with the version, so results from different runs never get mixed up.
  • Change one thing per version when you can. If v2 changes both the prompt and the model, you cannot tell which one broke a case.
  • Keep the old version runnable. A fast way back to v1 is your safety net. Module 9 shows how to switch back.

Keep the dataset stable between versions too. If you add cases, say so in your notes. Otherwise you compare different tests and call it progress. The Agent Launch Safety Checklist is a good place to add your release rule.

Conclusion and your next step

Regressions are normal when instructions, tools, models and knowledge keep changing. Run the same cases on both versions, label each one fixed, broken or unchanged, repeat flaky cases, and apply a release rule written in advance. Version everything so each result has a clear cause.

Your next step: take the dataset you have been building, mark three cases as must-pass and write a two-line release rule. Then continue to Practical Lab: Create an Agent Evaluation Suite, where you build the dataset, runner, scorer and comparison report for your own agent.

For related reading, see Evaluation Datasets, Rubrics and Expected Behaviours for choosing cases, and Measuring Accuracy, Task Completion and Tool Selection for reading scores honestly.

Common errors and how to fix them

A new prompt "improves" the score but a customer reports a new mistake.

Why it happens: Only totals were compared, so a broken case was hidden by fixed ones.

Fix: List fixed, broken and unchanged cases, and read every broken case before release.

Nobody can tell what caused a drop in results.

Why it happens: The prompt, the model and the settings all changed at once.

Fix: Change one thing per version, and record every setting in a versions file.

A case flips between pass and fail from run to run.

Why it happens: The model's answers vary, and a single run per case was used.

Fix: Repeat the case several times, report passes out of runs and judge the change on those counts.

The team argues about whether the result is good enough.

Why it happens: The release rule was written after the numbers were known.

Fix: Write the rule first. Tag cases that must pass and block any release that breaks one.

Validation checklist

Tick each item once you have confirmed it.

Hands-on exercise

Decide whether to release version 2

Change compare.py so that v2 returns status needs_person for E06 (the adversarial case) and the reply for E02 stays vague as in v1. Run it and write a release note with the counts, the three labels and your decision.

You will need

  • compare.py from this lesson.
  • Your two changes to the V2 text: E06 gets status needs_person, E02 gets the reply "Your order is on its way."

Acceptance criteria

Your work is done when every one of these is true.

Hints (3)
  • Edit the V2 lines only. Keep valid JSON on each line.
  • E05 and E06 both carry the must-pass tag.
  • If a case fails on both versions, it is unchanged. It still belongs on the to-do list.
Show a model answer

After the changes, v1 still passes 4 of 6. In v2, E02 stays failing, so it is unchanged. E04 is fixed. E05 is broken, because v2 answers a refund request instead of handing it over. E06 is broken, because it now returns needs_person where not_found was expected. That leaves v2 with 3 passes (E01, E03, E04), fewer than v1. Two must-pass cases are broken, so the decision is to hold the release and fix E05 and E06 first. The note should also say that totals alone would have shown v2 as worse, but that even a better total would not have been enough while a must-pass case is broken.

Knowledge check

Choose an answer, then check it. Nothing is recorded — this is for you.

  1. 1.Version 2 passes more cases than version 1, but one must-pass case now fails. What should you do?
    Show the answer and explanation

    Answer: B. The release rule protects the cases that must always pass, whatever the total says. Releasing on the total is tempting, but it ignores the one failure that matters. Removing the case hides the problem rather than solving it.

  2. 2.Why change only one thing between v1 and v2 when you can?
    Show the answer and explanation

    Answer: B. With several changes at once, a broken case could come from any of them. Running time does not depend on this, and models do not limit how many changes you make. The cost is a muddled cause.

  3. 3.A case passed 5 of 5 runs on v1 and 3 of 5 runs on v2. What is the best reading?
    Show the answer and explanation

    Answer: B. Repeat runs show that the case became less reliable. Looking at one passing run on v2 would hide this. It is not fixed, since it used to pass every time.

Frequently asked questions

What is regression testing in AI?

It is re-running a fixed set of test cases after a change, such as a new prompt or model, to check that old behaviour still works. The key idea is to compare the new results with the old ones, case by case.

How do I test a new prompt version safely?

Keep the old prompt, run both versions on the same dataset, and compare each case. Check that no must-pass case broke, and read every case that changed before you release.

Do I need to rerun all tests when I change the model?

Yes. A new model can behave differently on prompts that did not change. Run the whole dataset, because you cannot predict which cases will move.

What is a flaky test in an AI agent?

A test that gives different results on different runs without any change to the agent. It is common with live models. Repeat the test several times and report how many runs passed.

Written by
PromptFable Editorial
Last updated 18 Nov 2026
Review
Reviewed by Waseem Nadir, Technical Reviewer
Last reviewed 27 Nov 2026

References

Primary sources for the technical details in this lesson. Vendor platforms change — check the official page if anything here looks different from what you see.

PromptFable is independent and is not affiliated with, endorsed by or sponsored by Anthropic, Google, OpenAI or any other vendor. Claude, Gemini, Google AI Studio and other product names are trademarks of their respective owners.