Sub topic 2
Prompt Builder and what a prompt template is
This chapter assumes you know the Salesforce data model (objects, fields, records), can find your way around Setup, and know what an Agentforce agent and a topic are. It also assumes you have written a basic prompt for a large language model (LLM) before.
What Prompt Builder is
Prompt Builder is the Setup tool where you create, edit, test, and manage prompt templates. You open it from Setup by searching for "Prompt Builder".
A prompt template is a saved prompt with placeholders. The placeholders are called merge fields. When the template runs, Salesforce replaces each merge field with real data, sends the finished text to an LLM, and returns the generated text.
A template has these parts:
- A name and an API name. The API name is how Flow and Apex refer to the template.
- A template type, which decides where the template can be used. Chapter 3 covers the types.
- The prompt body, with instructions and merge fields.
- One or more versions. See the later chapter on versions and activation.
A first template
This template summarizes a case for a call hand-off. It takes a Case record as input and inserts four of its fields.
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.The text has two kinds of content. The merge fields, such as {!$Input:Case.Subject}, bring in record data. The sentences around them tell the model what to do and what to avoid. The next chapter on inputs and merge fields explains the syntax in detail.
How a template runs
The template does not decide when it runs. Something else calls it: a user in Prompt Builder, a Lightning page, a Flow, Apex code, or an agent.
Template versus agent instructions
Both are text that guides an LLM, so they are easy to confuse. They do different jobs.
| Row | Prompt template | Agent topic instructions |
|---|---|---|
| Purpose | Produce one piece of generated text | Guide the agent's decisions in a conversation |
| Data | Merge fields filled from records, Flow, or Apex | Whatever the user and the actions provide |
| Runs | When called, with defined inputs | Whenever the agent reasons about a user request |
| Reuse | Callable from agents, Flow, Apex, and pages | Belongs to one topic of one agent |
Topic instructions tell the agent when to call an action. The template defines what that action writes.
A template versus other action types
An agent action can be a Flow, an Apex method, or a prompt template, among others. Flows and Apex can read and change data. A prompt template only generates text from the data you give it. It does not update records, send email, or call other systems.
Choose a template when the result is text that the model must write, such as a summary, a draft reply, or a description. Choose a Flow or Apex action when the agent must do something deterministic, such as creating a record or calculating a value.
Common errors at this stage
- Vague output rules. Without limits such as sentence count or "use only the information above", the model adds invented detail. Put the rules in the template, not only in the agent.
- Empty merge fields. If a field such as Description is blank, the model gets an empty line. Tell it to say "unknown" instead of guessing.
- Wrong object. A template built around Case cannot read Contact fields unless you pass or relate them. Check the related object and the input type first.
- Fields the user cannot see. Data access follows the permissions of the running user, so a merge field may come back empty for one user and filled for another.
Exercise
A teammate wants an agent to close a case and then write a summary of it. Which part should be a prompt template, and which part should be another action type?
Show answer
The summary should be a prompt template, because it is generated text. Closing the case changes data, so it needs a Flow or Apex action. A prompt template cannot update records.