Sub topic 2
What a prompt template contains
This chapter assumes you know Salesforce objects, records, fields and relationships, and can find your way around Setup in Lightning Experience. It also assumes Einstein generative AI is enabled in your org, which Prompt Builder requires. You don't need to have built a template before.
A template is a saved, reusable prompt
A prompt template is a stored prompt that Salesforce fills with real data each time it runs. You write the instructions once. At run time, placeholders in the text are replaced by values from a record, and the finished prompt goes to a large language model (LLM). Because the instructions are saved and versioned, different users and automations get consistent output.
The parts of a template
Every template has the same building blocks, whatever its type.
| Part | What it does |
|---|---|
| Type | Sets the use case, the inputs the template accepts, and where its output can appear. |
| Name and API name | The label people see and the unique name that code and flows use to refer to the template. |
| Description | A note for admins about the template's purpose. It is not sent to the model. |
| Inputs | The data the template starts from, usually a record of a specific object. Flex templates let you define your own inputs. |
| Prompt text | The instructions and context sent to the model. |
| Resources | Placeholders inside the prompt text that pull in data. |
| Model | The LLM that processes the prompt. |
| Version and status | A numbered snapshot of the template that is either draft or active. |
Prompt text and resources
The prompt text is ordinary language, written like instructions to a colleague. A good one states the task, gives the context, and sets limits such as length and tone.
Resources are what make the prompt specific to your data. The most common resource is a merge field, which points at a field on the input record. At run time Salesforce replaces it with the field's value. The syntax shows the source: {!$Input:Account.Name} means the Name field of the record supplied as the input called Account.
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.This prompt has three parts. The first line is the task. The next three lines supply data through merge fields. The last line tells the model what to do with missing data. The next chapters cover grounding in more depth.
Besides merge fields, the resource picker can insert data from related records, flows, Apex and Data Cloud. Which of these are available depends on the template type and your org's setup.
Inputs and the template type
The type determines the inputs. A Sales Email template is built around a contact or lead and a related record, while a Field Generation template is built around one record of a chosen object. A Flex template lets you declare the inputs yourself. The merge fields you can use come from those inputs. If the input is an Account, you can reference account fields and fields reached through its relationships. You can't reference fields of an unrelated object.
Model and Trust Layer
Each template is tied to a model. You can usually keep the default or pick another model your org makes available. The prompt does not go to the model directly. It first passes through the Einstein Trust Layer, which applies data protections before and after the model call. A later chapter covers this.
Versions and status
Saving changes creates a version of the template. A version is either a draft you can still edit or an active version that other parts of Salesforce can use. Only one version of a template is active at a time. You can preview a draft against a real record before activating it, which lets you check the resolved prompt and the output.
Common errors
- Empty output or blank values: the merge field points at a field the record doesn't have filled in. Add an instruction for empty values, as in the example above.
- Wrong input name: the name after
$Input:must match the template's input. A Flex template with an input calledCaseneeds{!$Input:Case.Subject}, not{!$Input:Account.Name}. - Invented details: if the prompt doesn't forbid it, the model may fill gaps with guesses. State the limits in the prompt text.
Exercise
A teammate writes a Field Generation prompt that includes {!$Input:Contact.Title}, but the template's input is an Account record. Which template part is the problem, and why?
Show answer
The inputs. Merge fields can only reference the input record and the records reachable from it through relationships. A Contact merge field doesn't match an Account input, so it will not resolve to a value. The fix is to change the input, or to reach the data through a relationship that the Account input actually has.