Sub topic 2
What a prompt template contains
A prompt template is a saved, reusable set of instructions for a large language model (LLM). It is more than a block of text. This chapter breaks a template into its parts, so you know what you are filling in when you open Prompt Builder and what each part controls.
This chapter assumes you know basic Salesforce concepts (objects, records, fields, relationships) and can move around Lightning Experience and Setup. It also assumes you know roughly what a prompt is, and that Einstein generative AI is enabled in your org. The previous chapter covered why templates exist. The next one compares the template types.
The parts of a template
Every template in Prompt Builder is built from the same few parts. Which parts you see depends on the template type, but the overall shape stays the same.
| Part | What it holds | Why it matters |
|---|---|---|
| Name and API name | A label for people and a unique identifier for code | Flows, Apex, and metadata refer to the template by API name |
| Description | Free text explaining the purpose | Helps admins find and reuse templates |
| Template type | Sales Email, Field Generation, Record Summary, or Flex | Decides the available inputs and where the output can be used |
| Inputs | The record or data the prompt is based on | Gives the prompt something real to work with |
| Prompt text | Instructions plus merge fields and resources | The content the model receives |
| Model | The LLM that processes the prompt | Affects quality, style, and cost |
| Versions | Saved snapshots of the template | Lets you edit and compare without breaking live use |
The diagram shows how these parts fit together.
Name, API name, and description
When you create a template, you give it a name and, in most cases, an API name. The name is for people. The API name is the unique identifier that other parts of Salesforce use to call the template.
Choose the name carefully, because renaming a template that automation already references can cause confusion. Use a consistent convention, such as a prefix for the business area. Use the description to say what the template is for, who should use it, and which object it targets. Six months later, "CaseSummaryMgr" with a clear description is much easier to manage than "Prompt 2".
The template type
The type is the most consequential choice, and you make it first. It sets the following:
- Which inputs the template takes (a specific object record, or flexible inputs).
- Which resources and merge fields the editor offers.
- Where the output can appear in Salesforce, such as an email composer, a record field, or a record page summary.
Because the type shapes everything else, you generally can't switch a template to another type after you create it. You create a new template and copy the prompt text across. The next chapter compares the four types. For now, treat the type as the template's contract with the rest of the platform.
Inputs
Inputs tell the template which data it works with. There are two models:
- Object-bound types (Sales Email, Field Generation, Record Summary) are based on one object, such as Contact, Account, or Opportunity. When the template runs, it receives one record of that object.
- Flex templates take inputs that you define. An input can be a record of an object you choose, or free text. You can define more than one.
The input name drives the merge field syntax. For an object-bound template based on Contact, the input is Contact, and you reference its fields like this:
{!$Input:Contact.FirstName}For a Flex template, the name you give the input is what appears after $Input:. If you create an input called Case of type Case record, you write {!$Input:Case.Subject}. If you name it SupportCase, you write {!$Input:SupportCase.Subject}. Mismatched input names are a common reason a merge field fails to resolve.
The prompt text
The prompt text is what you write in the editor. It usually combines three kinds of content.
- Instructions. What the model should do, such as "Write a short follow-up email."
- Constraints. Length, tone, format, and what to avoid, such as "Keep it under 120 words and do not invent product details."
- Grounding data. Merge fields and resources that the platform replaces with real values before sending the prompt to the model.
Here is a small example for a Contact-based template.
Write a short, friendly follow-up email to {!$Input:Contact.FirstName} {!$Input:Contact.LastName}, who works at {!$Input:Contact.Account.Name}.
Mention that we met recently and offer to schedule a call.
Keep it under 120 words and do not invent product details.Before the model sees anything, Salesforce resolves each {!...} expression. If the Contact is Maria Lopez at Northwind, the model receives "Write a short, friendly follow-up email to Maria Lopez, who works at Northwind." The model never sees the curly-brace syntax. This is what "grounding" means: the model works from your CRM data instead of guessing.
The instruction lines are plain text, and the model treats them as instructions. Write them as you would brief a colleague: clear, specific, and with the limits stated.
Merge fields and resources
Merge fields are placeholders for field values. Dot notation follows relationships, so {!$Input:Contact.Account.Name} reaches the parent Account's name through the Contact's lookup. Insert them with the editor's resource picker instead of typing them by hand, which avoids typos in field API names.
Resources go beyond a single field value. Depending on the type and your org setup, the editor can offer:
| Resource | What it adds | Typical use |
|---|---|---|
| Merge fields | Single field values from the input record or its parents | Names, industries, amounts |
| Related lists | Child records of the input record | Recent cases, open opportunities |
| Flow | Data or text produced by a Flow | Calculated values, conditional logic |
| Apex | Data returned by an Apex class | Complex queries or formatting |
| Other templates | The output of another prompt template | Reusing a shared snippet |
Check which of these your org and template type offer. Availability varies by type and by release. Of these, merge fields and related lists are the simplest. Flow and Apex resources need someone to build the Flow or Apex class first, and they run with their own access rules.
Keep two limits in mind. First, a resolved value is only as good as the record. An empty field becomes an empty string, and the model may try to fill the gap with an invented value. Second, the more data you merge in, the longer the prompt gets. Long prompts cost more and can crowd out your instructions.
A common defense against the first problem is to state the rule in the prompt:
Using the information below, write a one-sentence description of this account for a sales rep.
Account name: {!$Input:Account.Name}
Industry: {!$Input:Account.Industry}
Annual revenue: {!$Input:Account.AnnualRevenue}
If a value is empty, leave it out instead of guessing.The model
Each template is associated with a model. Prompt Builder offers a default model and, depending on your org's configuration, other models you can pick from. The model choice affects output quality, response style, and speed. The prompt text stays the same when you switch models, but the output may differ, so preview again after any change.
Whichever model you choose, the prompt goes through the Einstein Trust Layer on its way to the model, which handles protections such as masking sensitive data. A later chapter covers that in detail. For now, remember that the layer sits between the template and the model, and you don't build it into the template yourself.
Versions
A template is not a single editable object. It holds one or more versions. Each version stores the prompt text, the model, and the settings at the time you saved it. This design has practical consequences:
- You can draft a change as a new version while an earlier version stays in use.
- Only one version of a template is active at a time. Activating a version is what makes the template available to features, Flows, and other callers.
- An active version is meant to be stable. To change it, you create a new version instead of editing it in place.
- You can preview and compare versions side by side before activating.
This means "the template" in conversation can refer to the whole container or to one version. When someone says "the template changed," ask which version.
How the parts work at run time
When something invokes an active template, the platform follows this order:
- It identifies the active version of the template.
- It reads the input, such as one Contact record.
- It resolves merge fields and resources into real values.
- It passes the resolved prompt through the Trust Layer.
- It sends the prompt to the chosen model and returns the response to the caller.
Knowing this order helps with debugging. If the output is wrong, check the resolved prompt first. The usual causes are an empty field, a mismatched input name, or a missing permission, and each of these happens before the model is involved. Check the model and the wording only after you have ruled those out.
Common mistakes
- Typing merge fields by hand. A wrong field name often shows up as a blank value. Use the resource picker.
- Forgetting the input name. In Flex templates,
{!$Input:Case.Subject}fails if the input is calledSupportCase. - Leaving out constraints. Without a length limit or a "do not invent" rule, outputs vary widely.
- Overloading the prompt. Merging every field on a record adds noise. Include what the task needs.
- Editing the live version. Create a new version, preview it, then activate it.
Exercise
A Flex template has an input named SupportCase that holds a Case record. You write "Summarize: {!$Input:Case.Subject}" and the subject comes back empty in the preview, even though the case has a subject. What is the most likely cause, and how do you fix it?
Show answer
The merge field uses the name Case, but the input is named SupportCase. The input name sets the merge field syntax, so the expression doesn't resolve. Change it to {!$Input:SupportCase.Subject}, ideally by inserting it with the resource picker, and preview again.
Exercise
List the five steps the platform takes when it runs an active template, in order, and name which step you would inspect first when the output mentions a wrong or missing customer name.
Show answer
(1) Identify the active version. (2) Read the input record. (3) Resolve merge fields and resources. (4) Pass the resolved prompt through the Einstein Trust Layer. (5) Send it to the model and return the response. Inspect step 3 first, because a missing or wrong name usually comes from an empty field, a mismatched input name, or a field the running user cannot access.