Sub topic 5
Asserting the expected topic
This chapter assumes you know what an Agentforce agent is, how topics and actions fit together, and how a test case is laid out (an utterance plus expectations). Here you learn how to assert the expected topic and how to fix the errors that come up most often.
What the topic assertion checks
When a user sends an utterance, the agent first picks one topic. A topic is a group of instructions and actions for one job, such as order status or returns. The topic assertion checks that the agent picked the topic you named. It does not check what the agent then said or did. Those are separate assertions.
Topic routing is the first decision in a conversation. If it is wrong, the actions and the answer are usually wrong too. A test that fails on topic tells you where to look first.
Writing the assertion
In a YAML spec, set expectedTopic to the topic's developer name. The developer name is the API-style name, not the label shown in the builder.
testCases:
- 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.In the Testing Center UI, you pick the topic from the agent's topic list, so a typo is less likely there. In a YAML or CSV file, the value is plain text, so you must type it exactly.
Out-of-scope requests
Some requests should not match any of your topics. The agent should decline them. In the sample spec from this tutorial, the pizza question expects Off_Topic:
- utterance: What is the best pizza recipe?
expectedTopic: Off_Topic
expectedActions: []
expectedOutcome: The agent politely declines and explains what it can help with.Use the developer name of the topic that handles out-of-scope requests in your own agent. If your agent has no such topic, check how it reports declined requests and match that. Write expectedActions: [] so the test also confirms that no action ran.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Topic mismatch on every case | Label used instead of developer name, or a typo | Copy the developer name from the topic's detail page |
| One case fails, similar cases pass | The utterance sits between two topics | Rewrite the utterance, or sharpen the topic descriptions |
| Test passes, then fails after an edit | A topic was renamed or its description changed | Update the spec, then rerun the whole suite |
| Out-of-scope case routes to a real topic | Topic descriptions are too broad | Narrow the descriptions and add scope limits |
Tips for stable topic tests
- Test each topic with at least two differently worded utterances. One passing phrase does not show the routing is reliable.
- Add one case for each pair of topics that sound alike, such as order status and returns.
- Keep utterances realistic. Users write short, messy text.
- Rename a topic only when you also update every spec that names it.
Exercise
A test for "I want to send my jacket back" expects the topic Order_Status, but the agent routes to Returns and the test fails. The agent's behavior looks correct to you. What should you change, and why?
Show answer
Change the test, not the agent. Set expectedTopic to the developer name of the Returns topic, because the utterance is a return request. The assertion was wrong. Then check that Order_Status still passes for its own utterances, such as "Where is my order 1001?".