Sub topic 13
Design Practices and Pitfalls
This chapter closes the tutorial. It collects the design rules that keep a prompt template action reliable, and it lists the failures you are most likely to meet. It assumes you have read the earlier chapters. You should know what a prompt template is, how merge fields ground a response, how a topic invokes an action, and how to test in Prompt Builder and Agent Builder.
Design for one job per template
A prompt template action works best when it does one narrow task. "Summarize a case for a call hand-off" is a good job. "Summarize the case, suggest next steps, draft an email, and estimate churn risk" is four jobs in one prompt.
Narrow templates help in three ways:
- The agent can pick the right action from its name and description. Several focused actions are easier to choose between than one action that does everything.
- You can test and fix one behavior at a time.
- You can reuse the template from Flow or Apex without carrying along unrelated output.
If two tasks share the same grounding data, you can still keep them as two templates. A second template costs little. A confusing action costs a lot of debugging.
Keep the split of responsibilities clear
The agent, the topic and the template each have a role. Most design mistakes come from putting a rule in the wrong place.
| Layer | Owns | Does not own |
|---|---|---|
| Topic scope and instructions | When to run the action, what to ask the user first, what to do with the output | The wording and structure of the generated text |
| Prompt template | How the text is written, which data is merged in, output rules | Deciding whether the user's request should trigger it |
| Action inputs and outputs | The contract between agent and template | Business rules |
| Flow or Apex resource | Getting or computing data the record does not hold | Tone and format of the answer |
The following diagram shows how a request moves through these layers.
When a result is wrong, find the stage that failed before you change anything. A wrong topic choice, a wrong input and a bad prompt all look like "the agent gave a bad answer", but each has a different fix.
Write the template defensively
The template body is the only place where you control the text the model sees. Treat it as a specification.
Ground the answer and name the fallback
State that the model must use only the supplied data, and say what to do when data is missing. The example from this tutorial does both:
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.Without the "say it is unknown" rule, an empty Description field gives the model room to invent a plausible one. Empty merge fields are the most common cause of invented details.
Limit the output
Set length, format and forbidden content in the template. Rules such as "at most five sentences" and "do not promise refunds" are cheap to write and easy to test. Put the rule about commitments in the template and also in the topic scope. A rule stated in both places holds up better when one of them is edited later.
Keep the prompt small
Every field you merge adds tokens, cost and noise. Merge only the fields the task needs. Long text fields such as email bodies and case comment histories can push important facts out of the model's useful attention or exceed the context limit. If you need a long history, summarize it first in a separate step, or pass a limited set of related records.
Plan for data access and permissions
Grounding data is only as good as the access behind it. Check these points before you call a template finished:
- Decide which user the template runs as. Data the running user cannot see will not appear in the prompt, and the output will silently lose facts.
- Confirm that the agent's running user, and any user who tests in Prompt Builder, has access to the objects and fields the template references.
- Confirm that Flow and Apex resources used for grounding respect the sharing and field-level security you intend. Apex that runs in system mode can return data the user should not see.
- Remember that the Einstein Trust Layer masks sensitive data and applies its safety checks, but it does not replace access design. If a field should never reach a prompt, do not merge it.
A template that works for an administrator and fails for a service agent is almost always an access problem, not a prompt problem.
Write topic instructions that are checkable
Topic text is read by the agent's reasoning engine, so vague wording produces unpredictable behavior. Compare these two instructions.
| Weak | Stronger |
|---|---|
| Help with cases. | Handles requests to summarize a support case for a colleague or a customer call. |
| Summarize if appropriate. | When the user asks for a case summary, ask for the case number if it was not given. |
| Return a good answer. | Return the action output without rewriting the facts. |
Follow these practices:
- Name the action in the instruction, using the same label the action has in the topic.
- State the precondition, such as "ask for the case number if it was not given".
- State what to do with the output. If you do not, the agent may paraphrase it and change facts.
- Put exclusions in the scope, for example "Does not create or update cases".
- Keep topics apart. If two topics have overlapping classification descriptions, the agent may choose the wrong one.
Common pitfalls
The agent never calls the action
Likely causes are an unclear classification description, an action description that does not match how users phrase the request, or an instruction that does not say when to run the action. Check the topic selection first, then the instruction text, then the action description.
The action runs with the wrong or missing input
If the agent passes an empty or guessed value, the action input is probably not marked clearly as required, or the instruction never tells the agent to collect it. Ask for the input in an instruction, and give the input a description that says what it is, such as "the Salesforce case number, for example 00001234".
The agent rewrites the template output
The template produced a correct summary, and the agent then added or changed details in its reply. Add an instruction to return the output as written. Check the output mapping too, so the agent receives the text and not only a status.
The template works in Prompt Builder but not in the agent
Prompt Builder previews use a record you pick and your own access. The agent supplies the input at run time and runs under its own user. Compare the input values and the permissions. Also confirm that the version the agent uses is the active one, since an edit saved to a draft version does not change the deployed behavior.
Hard-coded values and record IDs
A template that mentions a specific record ID, queue name or policy number breaks when the data changes or the template moves between orgs. Use merge fields and inputs. Keep policy text that changes often in a field or knowledge source that the template merges in.
Editing the active version
Changing a template that production agents depend on, without testing, changes live behavior. Make changes in a new version, test it in Prompt Builder and then through the agent, and activate it only after both pass. Keep the previous version available so you can switch back.
Testing only the happy path
A single good record proves little. Test records with empty fields, very long text, unusual statuses and a user with limited access. Test agent phrasing variations too, such as "give me the lowdown on 00001234" and "summarize that case".
A pre-release checklist
Use this list before you activate a template as an agent action.
- The template has one clear job and a label that describes it.
- The prompt merges only the fields it needs, and every merge field resolves for a realistic record.
- Rules cover length, allowed sources, the missing-data fallback and forbidden commitments.
- The agent's user can access every object, field, Flow and Apex resource that the template uses.
- The topic has a distinct classification description, a scope with exclusions, and an instruction that names the action and its output handling.
- Action inputs have descriptions, and outputs are mapped so the agent receives the generated text.
- You tested the template with edge-case records, and the agent with several phrasings.
- The new version is active, and the previous one is kept for rollback.
Reuse outside the agent
A well-designed template can serve other callers. The Apex example from earlier chapters calls the same Summarize_Case template by API name. When you reuse a template, keep the input names stable. Renaming an input in a template can break Flow and Apex callers as well as the agent action, so treat input names as part of a public contract and check all callers before you change them.
Exercise
A service agent reports that the Summarize Case action works for them in Prompt Builder previews, but in the live agent the summaries often say "Description: unknown" even when cases have descriptions. Name two likely causes and how you would check each.
Show answer
First, an access problem: the agent's running user may lack field-level access to Case.Description, so the field merges as empty. Check the running user's permission sets and field-level security for that field. Second, a wrong or stale version or input: the agent may be passing a different case than expected, or it may use an older active version of the template. Check the action input value in the Agent Builder test trace and confirm which template version is active. Previews run under your own access with a record you chose, so they can hide both issues.
Exercise
A topic instruction says "Summarize cases when appropriate." Rewrite it so the agent runs the action at the right time and does not alter the result.
Show answer
"When the user asks for a case summary, ask for the case number if it was not given. Once the case is identified, use the Summarize Case action and return its output to the user without rewriting the facts." This states the trigger, the precondition, the action name and the output handling.
Exercise
Why should you create a new template version for a change instead of editing the active version, and what should you test before activating it?
Show answer
Production agents use the active version, so an edit to it changes live behavior without testing. A new version lets you test safely and keeps the old version for rollback. Test it in Prompt Builder with normal and edge-case records, then through the agent in Agent Builder with several phrasings, and only then activate it.