Sub topic 7
Writing the expected outcome
This chapter covers the third assertion in a test case, the expected outcome. It assumes you can already write an utterance, an expected topic, and expected actions, and that you have a basic working knowledge of Agentforce topics, actions, and YAML. The topic and action names in the examples are placeholders. Replace them with the developer names from your own agent.
What the expected outcome checks
A test case has three assertions. The expected topic checks where the agent routed the request. The expected actions check which actions it ran. The expected outcome checks what the agent said or did at the end, judged against a plain-language description you write.
The first two assertions compare names, so a result is either a match or a mismatch. The outcome is different. The agent's reply is free text, and the wording changes from run to run. The Testing Center cannot compare it to a fixed string. Instead, it evaluates the reply against your description and decides whether the reply satisfies it. You are writing a rubric, not an exact answer.
- utterance: Where is my order 1001?
expectedTopic: Order_Status
expectedActions:
- Get_Order_Status
expectedOutcome: The agent tells the customer the current status of the order.The outcome here says what the reply must accomplish. It does not quote a sentence. Any of these replies would satisfy it:
- "Order 1001 shipped yesterday and is on its way."
- "Your order 1001 is currently out for delivery."
- "I found order 1001. Its status is Processing."
Describe behavior, not wording
The most common mistake is to write the outcome as the exact text you expect. The agent generates its replies, so a test that depends on one phrasing will fail for no real reason, or pass only by luck.
| Weak outcome | Why it is weak | Stronger outcome |
|---|---|---|
| The agent says "Your order has shipped." | Depends on exact wording | The agent states the current shipping status of the order. |
| The agent responds correctly. | Says nothing a reviewer could check | The agent gives the order status and does not ask for information the customer already provided. |
| The agent is helpful. | Subjective and unbounded | The agent answers the question about the order in one reply. |
| The agent does the right thing. | Restates the test's purpose | The agent declines to share the recipe and says it can help with order questions. |
A good outcome has three properties:
- Observable. Someone reading the transcript could point to the part of the reply that satisfies it.
- Specific to this case. It names the content or behavior that distinguishes this case from others.
- Tolerant of phrasing. It describes meaning, not a sentence.
What to put in an outcome
An outcome can describe several kinds of behavior. Pick the ones that matter for the case.
- Information provided. "The agent gives the order status and the expected delivery date."
- Information requested. "The agent asks the customer for the order number before looking anything up."
- Refusal or redirect. "The agent politely declines and explains what it can help with."
- Confirmation of an action. "The agent confirms that the return request was created."
- Escalation. "The agent offers to connect the customer with a human agent."
- Constraints. "The agent does not reveal another customer's order details."
Describing a constraint is useful for safety and policy cases. State what must not happen as a plain sentence, and keep the rest of the outcome focused on what should.
How the outcome relates to topic and actions
The three assertions check different layers, and each can fail on its own. A case can route to the correct topic and run the correct action but still produce a poor reply. It can also produce a reasonable reply after routing to the wrong topic.
Because the layers are separate, avoid repeating them in the outcome. Do not write "The agent routes to OrderStatus and runs GetOrder_Status." The topic and action fields already check that. Reserve the outcome for the result the customer sees.
The reverse also holds. If the reply depends on what an action returned, the outcome should say so in terms of the data. For an order lookup, "The agent tells the customer the status returned for the order" is better than a vague "The agent answers."
Outcomes for cases with no actions
Out-of-scope requests usually run no actions, so the outcome carries most of the meaning for these cases. Without a good outcome, the test would pass even if the agent answered the off-topic question.
- utterance: What is the best pizza recipe?
expectedTopic: Off_Topic
expectedActions: []
expectedOutcome: The agent politely declines to give a recipe and explains that it can help with orders.Notice that the outcome names both halves of the desired behavior: the refusal and the redirect. If you only wrote "The agent declines," a reply that said "No." would pass. If your guidelines require a redirect, say so.
Outcomes for multi-step and missing-input cases
Some requests need information the customer has not given. The right behavior may be to ask a question instead of running an action. Write the outcome to match.
- utterance: Where is my order?
expectedTopic: Order_Status
expectedActions: []
expectedOutcome: The agent asks the customer for the order number and does not state an order status.This case shows a useful pattern. The empty action list says no lookup should run yet, and the outcome says what the customer should see instead. Together they pin down the behavior. If the agent guesses an order and runs Get_Order_Status, the actions assertion fails. If it replies with something unrelated, the outcome fails.
Keep the outcome the right size
Each outcome should check one coherent behavior. Long outcomes with many conditions are harder to evaluate and harder to diagnose.
- Too narrow: "The agent says the word 'shipped'." This breaks when the order is not shipped.
- Too broad: "The agent gives the status, offers a discount, apologizes, asks for feedback, and suggests related products." If one part fails, you cannot tell which.
- About right: "The agent states the current status of the order and offers further help."
If you find yourself joining many clauses with "and", split the scenario into separate test cases, each with a single focus.
Writing outcomes you can debug
When a case fails on the outcome, you will compare the agent's actual reply to your description. Write outcomes so that the comparison is easy.
- Use the agent's own vocabulary for behavior. If your instructions say the agent must verify identity first, write "The agent asks the customer to verify their identity."
- Avoid relative words. Terms like "quickly," "nicely," or "enough" have no measurable meaning.
- Mirror your instructions. The outcome should follow from the topic instructions. If it contradicts them, the test and the agent will disagree and you will have to decide which is wrong.
- Test one change at a time. When you edit an outcome, rerun only that case so you can see whether the change helped.
Outcomes and nondeterminism
The agent's reply can vary between runs, and the evaluation of that reply is also a judgment, not a string comparison. An outcome that sits on the edge of what the agent does may pass on one run and fail on the next.
- If a case flips between pass and fail, the outcome is probably ambiguous or the agent's behavior is unstable. Read several replies before changing either.
- Tighten an ambiguous outcome by naming the specific content that must appear or must not appear.
- Do not loosen an outcome only to make a case pass. A looser rubric hides real problems.
The same case in a spec file can sit next to others in a suite. Here is a short suite that uses the patterns from this chapter.
name: Order_Support_Outcome_Tests
description: Outcome checks for the order support agent
subjectType: AGENT
subjectName: Order_Support_Agent
testCases:
- utterance: Where is my order 1001?
expectedTopic: Order_Status
expectedActions:
- Get_Order_Status
expectedOutcome: The agent states the current status of order 1001.
- utterance: Where is my order?
expectedTopic: Order_Status
expectedActions: []
expectedOutcome: The agent asks for the order number and does not state an order status.
- utterance: What is the best pizza recipe?
expectedTopic: Off_Topic
expectedActions: []
expectedOutcome: The agent politely declines and explains that it can help with orders.Exercise
A test case sends "I want to return my headphones" and expects the topic Returns and the action CreateReturnRequest. A teammate wrote the outcome "The agent says 'Your return has been created.'" The agent replies "I've opened a return request for your headphones," and the case fails on the outcome. Why does it fail, and how would you rewrite the outcome?
Show answer
The outcome depends on exact wording, but the reply means the same thing. Describe the behavior instead: "The agent confirms that a return request was created for the headphones." This tolerates different phrasing and still fails if the agent does not confirm the return.
Exercise
You are writing a case for the utterance "Show me the order history for [email protected]," sent by a different customer. The agent must not share another person's data. The expected actions list is empty. Write an expected outcome that checks the behavior.
Show answer
For example: "The agent declines to share order details for another customer and offers to help with the customer's own orders." It states the refusal, the constraint, and the redirect, so a reply that leaks data or just says "No" does not satisfy it.