Sub topic 13
Building and running a regression test set
This chapter assumes you can read a conversation and its reasoning trace, you have classified a failure (topic, action, instruction, grounding, or guardrail), and you have edited an agent in Agentforce Builder. Here you will turn real failures into repeatable tests and run them before each release.
Why a regression test set
A regression is a behavior that worked before and breaks after a change. Agents regress easily. Rewriting one topic description can pull utterances away from a neighboring topic. Adding an action can change which action the planner prefers. Because the model's choices depend on the wording of every topic and action, a fix in one place can shift behavior somewhere else.
A regression test set is a saved list of utterances with the behavior you expect for each. You run the whole list after every change. A passing run does not prove the agent is good. It shows that known problems stay fixed and known good behavior stays intact.
The test set sits between diagnosis and release in the improvement loop:
What a good test case contains
Each test case should state what the user says and what you expect the agent to do. Checking only the final wording is fragile, because the agent can phrase a correct answer many ways. Check the decisions that led to the answer.
A useful case has these parts:
- A name that describes the failure it guards against.
- The user utterance, or a short sequence of utterances for multi-turn cases.
- The expected topic.
- The expected action, or an explicit statement that no action should run.
- The expected response behavior, described as what the reply must or must not do.
Here is a case built from a real failure, where a returns request was routed to the order topic:
Test case: Returns request is not handled by the order topic
User utterance: I want to send back the shoes I bought last week.
Expected topic: Returns
Expected action: none until the order number is confirmed
Expected response: Asks for the order number or return reason, does not give a delivery date.The "expected response" line is written as behavior, not exact text. It says what the reply asks for and what it must not do. This keeps the case stable when the model words the reply differently.
Turning a failed conversation into a test case
Work from the conversation you reviewed, in this order:
- Copy the user's utterance as written. Real phrasing, with typos and vague wording, exposes weaknesses that tidy examples hide.
- Remove personal data. Replace names, order numbers, emails, and phone numbers with realistic placeholders. Test sets are shared more widely than production transcripts, so they should hold no customer data.
- Write the expected topic and action from what the agent should have done, not from what it did.
- Write the expected response as checkable behavior.
- Run the case against the current version first. It should fail. If it passes, the case does not capture the problem.
Step 5 matters. A test that never failed gives no evidence that your fix did anything.
Covering more than the failures
A set made only of past failures protects only against those failures. Aim for these groups:
| Group | Purpose | Example |
|---|---|---|
| Fixed failures | Keep known bugs fixed | The returns utterance above |
| Core happy paths | Confirm main jobs still work | "Where is my order 1234?" goes to Order Status and runs the lookup |
| Neighbor topics | Catch routing drift between similar topics | Cancellation, refund, and return requests |
| Paraphrases | Check that wording changes do not change routing | "Track my package", "Has my stuff shipped yet?" |
| Out of scope | Confirm the agent declines or escalates | A request for legal advice |
| Missing data | Check the fallback path | An order number that does not exist |
Include several paraphrases for each important intent. One phrasing passing tells you little about the intent as a whole.
Running the tests
You can run the set in two ways. In Agentforce you can use the testing tools in Setup, such as the Testing Center or the agent testing features in your org, to upload cases in bulk and review results per case. You can also test by hand in the Builder's preview panel, where the reasoning steps show the selected topic and action. Menus and file formats change between releases, so check the current Salesforce documentation for the exact upload format.
Whichever route you use, record for each case whether the topic, the action, and the response each passed. Separate results show where a failure sits. A case with the right topic but the wrong action points to action descriptions, not topic text.
Run the set against a sandbox or a draft version, never against live customers. Actions in a preview can read or write real records, so point them at test data.
Handling variability
An LLM can answer the same utterance differently on two runs. Treat results with that in mind:
- Rerun any failing case at least once before you conclude it failed.
- A case that fails sometimes is a real signal. It means the instructions leave room for more than one reading. Tighten them and rerun.
- Compare topic and action selection first. These are more stable than wording.
- Keep response checks to behaviors: asks for X, does not mention Y, offers a human.
Summarizing a run
Count results by group so you can see which area changed. The same group-by approach used for conversation metrics works here:
from collections import defaultdict
# Hypothetical results from one test run. Field names are illustrative,
# not an Agentforce schema.
results = [
{"case": "Returns not routed to orders", "group": "Fixed failures", "passed": True},
{"case": "Order status happy path", "group": "Core happy paths", "passed": True},
{"case": "Cancel vs return", "group": "Neighbor topics", "passed": False},
{"case": "Track my package", "group": "Paraphrases", "passed": True},
{"case": "Has my stuff shipped", "group": "Paraphrases", "passed": True},
]
by_group = defaultdict(lambda: [0, 0])
for r in results:
by_group[r["group"]][1] += 1
if r["passed"]:
by_group[r["group"]][0] += 1
for group, (passed, total) in by_group.items():
print(f"{group}: {passed}/{total} passed")
failed = [r["case"] for r in results if not r["passed"]]
print("Failing cases:", failed)Here the fix for returns held, but a neighbor-topic case failed. That points to the change having pulled cancellation requests toward the wrong topic.
Reading a failure after a change
When a case fails after an edit, open the reasoning trace for that run and compare it with the trace from the last passing version. Look at which topic was chosen and why. Then pick the smallest correction. Often it is a clearer exclusion in a topic description, such as the one in the earlier example:
BEFORE (topic description)
Handle questions about orders.
AFTER (topic description)
Handle questions about the status, tracking, and delivery date of an existing order. Do not handle returns, refunds, or cancellations.Change one thing at a time. If you edit three descriptions and a case breaks, you cannot tell which edit caused it.
Common mistakes
- Testing only the failing utterance. The fix passes while a neighbor topic breaks.
- Asserting exact reply text. Tests fail on harmless rewording and people stop trusting them.
- Keeping cases with real customer data. This creates a privacy problem in a place with wider access.
- Never retiring cases. When the business changes a policy, update or remove the cases that encode the old one.
- Running the set once. Run it after every change, and again on the final candidate version.
Exercise
A user says, "Can I cancel the order I placed this morning?" After you narrowed the Order Status topic to exclude cancellations, you want a regression case. Write the case with the expected topic, action, and response behavior. Then name one paraphrase to add.
Show answer
Test case: Cancellation request is not handled by the order status topic. User utterance: "Can I cancel the order I placed this morning?" Expected topic: Cancellations (or the topic that owns cancellations in your agent). Expected action: none until the order is identified. Expected response: asks for the order number or confirms the order, does not give a delivery date or tracking status. A paraphrase to add: "I changed my mind, please stop my order." Run the case on the version before your change to confirm it fails, then on the new version to confirm it passes.
Exercise
A test case passes on the first run and fails on the second, with no change to the agent. What does this tell you, and what do you do?
Show answer
The instructions or descriptions allow more than one reading, so the model's choice varies between runs. Rerun the case several times to see how often it fails. Open the reasoning trace of a failing run to see which topic or action was chosen. Then tighten the topic description, add an exclusion, or add explicit steps to the instruction, and rerun until the case passes consistently.