Sub topic 10
Testing and debugging the template and the agent
This chapter assumes you have built a prompt template such as the Summarize_Case template and added it to a topic as an action. It also assumes you can open Prompt Builder and Agent Builder in Setup and that you know what a topic, an instruction, and a merge field are. It covers how to check each layer separately and how to work out which layer is at fault when the result is wrong.
The working model: three layers, three places to test
A wrong answer from an agent can come from three different layers. Each layer has its own test tool.
| Layer | What can go wrong | Where to test |
|---|---|---|
| Template | Empty or wrong merge fields, weak rules, wrong model | Preview in Prompt Builder |
| Action wiring | Wrong input mapping, wrong output used | Agent Builder, action detail and conversation preview |
| Topic and instructions | Wrong topic chosen, action never called, output rewritten | Agent Builder conversation preview and its reasoning view |
Test from the bottom up. Get the template right first, then the action wiring, then the instructions. If you start with the agent, you cannot tell whether a bad summary came from missing data or from the agent ignoring the action.
Testing the template in Prompt Builder
Prompt Builder has a preview pane next to the template editor. For a template with a record input, you pick a sample record, such as a specific Case, and run the preview. You then see two things:
- The resolved prompt. This is your template text with every merge field replaced by real data.
- The response. This is the text the model returned for that resolved prompt.
Read the resolved prompt first. It shows what the model actually received, which is often different from what you intended to send.
What to look for in the resolved prompt
- A merge field that resolved to nothing. The line reads
Description:with no value. Either the field is empty on that record, or the running user cannot read it. - A merge field printed as literal text, which usually means a typo in the resource name.
- A related list or Flow output that is far longer than you expected. Long grounding data can crowd out your rules.
- Data from the wrong record, which happens when a Flow or Apex resource looks up records with the wrong filter.
Here is the template from the earlier chapters again. It is the baseline for the tests in this chapter.
You are a service assistant. Write a short, factual summary of the case below for a customer call hand-off.
Case number: {!$Input:Case.CaseNumber}
Subject: {!$Input:Case.Subject}
Status: {!$Input:Case.Status}
Description: {!$Input:Case.Description}
Rules:
- Use at most five sentences.
- Use only the information above. If something is missing, say it is unknown.
- Do not promise refunds or dates.Choose test records on purpose
One good preview proves little. Pick a small set of records that stress the template:
- A normal case with all fields filled in.
- A case with an empty
Description. The rule "If something is missing, say it is unknown" should show here. - A case with a very long
Description, to check the five-sentence limit. - A case whose description contains a request such as "refund me" or a promised date, to check the last rule.
- A case written in another language, if your users have those.
Run each one and compare the response against the rules in the template. A rule that the model breaks on one of these records needs to be stated more clearly, or it needs a concrete example in the template.
Model and Trust Layer effects
The same resolved prompt can give different wording with different models, so test with the model you plan to deploy. Also remember that the Einstein Trust Layer can mask sensitive values before the prompt reaches the model, and it can apply other safeguards to the response. If the response contains placeholder-like text or is missing a value you can see in the resolved prompt, check the Trust Layer settings and your masking configuration before you rewrite the template.
Testing the action wiring
After the template behaves, add or open it as an action in the topic and look at the action's inputs and outputs in Agent Builder. Check these points:
- Every required input of the template has a matching action input.
- The input description tells the agent what to supply. For a Case input, say that it needs a case record or case number, not "the input".
- The output is the generated text, and the instructions refer to it by the action's name.
A common mistake is an input the agent cannot fill. If the template needs a Case record, but nothing in the conversation or in an earlier action gives the agent a case ID, the agent will ask the user or guess. That is why the topic text asks for the case number when it is missing.
Testing the agent in Agent Builder
Agent Builder has a conversation preview where you chat with the agent as a user would. Alongside the chat, it has a reasoning or trace view. The exact name and layout change between releases, but it shows the steps the agent took for each message:
- Which topic the agent selected.
- Which action it chose, and the inputs it passed.
- What the action returned.
- The final reply.
This trace is your main debugging tool. Always read it before you change anything.
Write a test script
Keep a short list of utterances and the behavior you expect. A table works well.
| Utterance | Expected topic | Expected behavior |
|---|---|---|
| "Summarize case 00001026" | Case Hand-off | Calls Summarize Case with that case, returns the output unchanged |
| "I need a summary for my call" | Case Hand-off | Asks for the case number first |
| "Close case 00001026" | Not Case Hand-off | Does not call Summarize Case |
| "Summarize case 99999999" | Case Hand-off | Reports that the case was not found, does not invent facts |
Run the same script after every change to the template, the instructions, or the mapping. If your org has Agentforce Testing Center, you can store these utterances as test cases and run them as a batch, with expected topic and action checks. This catches regressions that a few manual chats will miss.
Diagnosing common failures
The agent never calls the action
Look at the trace. If the wrong topic was selected, the problem is the classification description, not the action. Make the description specific about what users ask for.
Classification description: Handles requests to summarize a support case for a colleague or a customer call.If the right topic was selected but no action ran, the instructions are probably vague. Compare these two:
Weak: Help the user with case summaries.
Strong: Once the case is identified, use the Summarize Case action and return its output to the user without rewriting the facts.Name the action exactly as it appears in the topic, and say when to use it.
The action runs with the wrong or missing input
Check the input values in the trace. The agent may have passed the case number where the template expects a record ID, or passed nothing. Fix the input description, and consider adding an instruction that tells the agent how to find the record before it calls the action.
The summary is empty, thin, or wrong
The cause is almost always in the resolved prompt. Open the template preview with the same record. If the preview is good but the agent's answer is poor, the agent is probably rewriting the output. Add an instruction to return the output as is.
The output ignores a rule
Move the rule closer to the end of the template, make it one short sentence, and state it positively where you can. Then rerun your records from the earlier list. Do not add a dozen new rules at once. Change one thing, retest, and keep what helped.
The result differs between users
Compare field-level security, object permissions, and permission set assignments for the agent's running user and for the user in the test. Differences in data access change the resolved prompt even when the template text is identical.
A debugging routine
- Reproduce the problem in the Agent Builder conversation preview and keep the exact utterance.
- Read the trace: topic, action, inputs, output.
- If the action did not run, fix the classification or instructions.
- If the inputs were wrong, fix the action input descriptions or the lookup step.
- If the inputs were right, open the template in Prompt Builder, preview it with the same record, and read the resolved prompt.
- Fix the template, rerun your test records, then rerun the agent script.
Exercise
A user types "Summarize case 00001026". The Agent Builder trace shows the correct topic and a call to Summarize Case with the right case. The reply contains a promised refund date, which the template forbids. Which layer do you check first, and what do you look at?
Show answer
Check the template layer first. Open Prompt Builder, preview the template with case 00001026, and read the resolved prompt and the response. If the preview response also contains the refund date, the rules or the case text need work. If the preview response is clean, the agent is rewriting the action output, so add or tighten the topic instruction to return the output without rewriting the facts.
Exercise
Your template previews well for you, but the agent returns "unknown" for the case description on the same record. Give two likely causes.
Show answer
The agent's running user may lack field-level read access to Description, so the merge field resolves to empty. The action input mapping may also pass a different or empty record, so the template resolves against the wrong data. Check the permissions of the running user and the input value in the trace.