Sub topic 2
Prompt Builder and what a prompt template is
This chapter explains what a prompt template is, where you create one, and how it differs from the other things that shape an Agentforce agent. It assumes you know the Salesforce data model (objects, fields, records) and can work in Setup and with permission sets. It also assumes you know what an Agentforce agent and a topic are, and that you have basic experience prompting a large language model (LLM). Later chapters cover template types, input resources, grounding, and the Trust Layer in detail. Here you build the working model that those chapters extend.
What a prompt template is
A prompt template is a saved, reusable prompt. It is made of fixed text, which holds your instructions, and placeholders called merge fields. At run time, Salesforce replaces each merge field with real data, such as a field from a Case record. It then sends the finished text to a large language model and returns the generated response.
A template has these properties:
- Parameterized. The same template works for any Case, because the case data comes in as an input.
- Governed. It has a name, an API name, versions, and an active or inactive state. Admins control who can create it and who can run it.
- Deterministic in structure. The text you wrote is always sent. The model decides only what it generates in response to that text.
- Callable from several places. An agent, a Flow, Apex code, or a record page can run the same template.
The last point matters for this tutorial. A prompt template is the unit of reusable generation. An Agentforce agent can use it as an action, but the template does not belong to the agent.
Where you build it: Prompt Builder
Prompt Builder is the Setup tool for creating, testing, and managing prompt templates. Open it by searching for "Prompt Builder" in Setup. It has three working areas:
- A template list. It shows each template with its type, status, and versions.
- An editor. You write the prompt text and insert resources (inputs, related data, Flow, Apex) with the resource picker or by typing merge field syntax.
- A preview pane. You choose a real record, resolve the prompt against it, and see both the assembled prompt and the model's response.
Two permission sets control access. Prompt Template Manager lets a user create and edit templates. Prompt Template User lets a user run them. Your org must also have Einstein generative AI turned on before Prompt Builder is available.
Anatomy of a template
When you create a template, you choose a type and give it a name. The template's API name is what Flow, Apex, and other callers use to find it. For a Flex template you also declare the inputs, for example one input of type Case. The sample below is the body of a Flex template that summarizes a case for a call hand-off.
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 template has three parts.
Role and task. The first line tells the model who it is and what to produce. Say what the output is for ("a customer call hand-off"), because the purpose affects tone and length.
Grounding data. The four lines with {!$Input:Case...} are merge fields. In {!$Input:Case.Subject}, $Input says the value comes from a declared input, Case is the name of that input, and Subject is the field. If the Case has a Subject of "Router keeps rebooting", the model sees exactly that text in place of the merge field. If a field is empty, the model sees an empty value, which is why the rules tell it to say "unknown".
Rules. The closing list limits the output. Each rule is specific and testable: a sentence count, a restriction to the supplied data, and a ban on commitments. Vague rules such as "be helpful and accurate" are hard to test and change little.
How a template runs
Whatever calls the template, the same sequence happens. The caller names the template and supplies the inputs. Salesforce resolves the merge fields from the record, applies data masking and other protections through the Einstein Trust Layer, sends the prompt to the selected model, checks the response, and returns the text.
Two consequences follow:
- Data access is checked when the template runs. Merge fields read only what the running user is allowed to see. A template that works for you in the preview can return blanks for a user who lacks field access.
- The model never sees your template as a template. It sees one long piece of text with the values already inserted. When output is wrong, the first thing to inspect is that assembled text. Prompt Builder's preview shows it.
Prompt template versus agent instructions versus other actions
The tutorial's central question is how a prompt template differs from the other ways you control an agent. These tools have different jobs.
| Aspect | Topic instructions | Prompt template | Flow or Apex action |
|---|---|---|---|
| Purpose | Tell the agent when and how to act | Generate text from a fixed prompt and grounded data | Run logic, read data, or change data |
| Written in | Natural language in Agent Builder | Natural language with merge fields in Prompt Builder | Flow Builder or Apex code |
| Output | Guides the agent's decisions | Generated text | Structured values or record changes |
| Reuse | Within the agent's topic | Agent, Flow, Apex, record pages | Agent, Flow, Apex, other automation |
| Versioned on its own | No | Yes | Flow versions, Apex deploys |
| Predictable | The agent still interprets it | The prompt text is fixed, the generated text varies | Mostly deterministic |
Topic instructions steer the agent's reasoning, for example "when the user asks for a case summary, ask for the case number". The agent interprets them, so they influence behavior but do not guarantee it. A prompt template does not decide whether to run. It defines what happens once something calls it. Flow and Apex actions do work on data. A prompt template only generates text. If the task is "update the case status", use a Flow or Apex action. If the task is "write a summary of the case", a prompt template fits.
The split also affects maintenance. Put the knowledge about how to write the summary (tone, length, banned promises) in the template. Put the knowledge about when to offer a summary in the topic. Then you can change the wording of summaries without touching the agent, and the other way round.
Why use a template instead of free-form agent output
An agent can already answer from its own instructions and the conversation. Use a template when you need one or more of these:
- Consistent structure. Every summary has the same shape and rules.
- Controlled data. You choose exactly which fields and related records go into the prompt, rather than hoping the agent finds them.
- Reuse. The same wording is used in the agent, in a Flow that runs on case close, and in an Apex class.
- Testing before release. You can preview against real records and compare versions before any user sees the output.
- Model choice. You can select the model for this one task.
The cost is added maintenance. Each template is another artifact with versions, permissions, and tests. A one-off question that no other process will reuse may not justify one.
Common errors
These problems appear often at the stage of first building a template.
- Empty merge fields. The reference may be misspelled, the field may be blank on the record, or the user may lack field-level access. Check the resolved prompt in the preview, not only the model response.
- Instructions that conflict with data. If the rules say "use only the information above" but the template provides almost no data, the model produces generic or evasive text. Add the fields it needs.
- Rules that cannot be tested. "Keep it short" is not checkable. "At most five sentences" is.
- Treating the template as the agent. The template does not ask follow-up questions or decide when to run. If the case number is missing, the template cannot ask for it. That is a topic instruction's job.
- Editing a live template without testing. Changes to wording can change output for every caller. Later chapters cover versions and activation, which exist to prevent this.
What comes next
This chapter fixed the vocabulary: a template is saved prompt text with merge fields, built and tested in Prompt Builder, run by a caller, and separate from topic instructions. The next chapters take each part further. You will choose a template type, work with input resources and related data, learn what the Trust Layer does, and then connect the template to an agent as an action.
Exercise
A team wants an Agentforce agent to (1) decide when a customer asks for a case summary, (2) ask for the case number if it is missing, and (3) produce a five-sentence summary that never promises refunds. Which of these three belong in topic instructions, and which belong in a prompt template?
Show answer
Items 1 and 2 belong in topic instructions, because they are about when the agent acts and what it asks the user. Item 3 belongs in the prompt template, as rules in the template text (at most five sentences, no promises of refunds). The template can also be reused by a Flow or Apex without repeating those rules.
Exercise
A preview of your Case summary template returns "Subject: " with nothing after it, although the case has a subject. Name two likely causes and where you would look first.
Show answer
Likely causes are a misspelled merge field reference, such as the wrong field name after Case., and missing field-level access for the user running the template. Look first at the resolved prompt in Prompt Builder's preview to see whether the value was inserted, then check the merge field syntax and the user's field permissions.