Sub topic 2
Prompt templates and template types
What this chapter covers and what it assumes
This chapter explains what a prompt template is in Salesforce Prompt Builder, which template types exist, and how the type controls the inputs and resources you can use. It assumes you know the basic Salesforce data model (objects, fields, relationships), can navigate Setup and assign permission sets, and understand that a large language model (LLM) takes a text prompt and returns generated text. Later chapters cover merge fields, Flow, and Apex in detail. Here you build the frame they all fit into.
What a prompt template is
A prompt template is a reusable block of instruction text with placeholders. When a user or process runs the template, Salesforce replaces each placeholder with real data, which is called resolving the template. The resolved text becomes the prompt that goes to the LLM.
A template has these parts:
- Name and API name. The label people see and the stable identifier that other features reference.
- Type. Determines where the template can be used and what inputs it takes.
- Inputs. The records or values the template is anchored to. The next chapter covers these.
- Prompt body. The instruction text, with merge fields and resource references.
- Model. The LLM that receives the resolved prompt. You can usually keep the default.
- Versions. Each template can have several versions, so you can edit and test a new one while an older one stays active.
The key point is separation. The instruction text is written once and reviewed once. The data changes on every run. This is how you ground the prompt in current CRM data without writing new prompts by hand.
Where templates are built
You create and edit templates in Prompt Builder, found in Setup by searching for "Prompt Builder". It has a template list and an editor. The editor shows the prompt body next to a settings panel. You insert merge fields and resources with an Insert Resource control or by typing the placeholder syntax directly. A preview panel lets you resolve the template against a real record before you activate it. The preview is covered in a later chapter.
Using Prompt Builder normally requires a permission set that grants access to it, and users who run templates need access to the template and to the data it reads. Names and licensing of these permission sets change between releases, so check the current Salesforce documentation for the exact ones in your org.
Template types
The template type is the most important choice you make when creating a template. It sets the purpose of the template, where it can run, and what input it requires. The common types are listed below. Availability depends on your org's edition and release, so confirm in your own Prompt Builder.
| Type | What it produces | Typical input | Where it runs |
|---|---|---|---|
| Sales Email | A drafted email to a contact or lead | A contact or lead, often with a related record | Email composer on records |
| Field Generation | Text that fills a field on a record | A record of one object | A field on a Lightning record page |
| Record Summary | A summary of a record | A record of one object | A Lightning record page |
| Flex | Free-form output | One or more inputs you define, such as records or text | Flows, Apex, the Einstein Trust Layer APIs, and Agentforce |
Treat this table as a map and not a full catalog. Salesforce adds and renames types over time. The pattern holds across them: a type narrows the template to one job and decides what you can ground it with.
Why the type matters
The type affects three things.
- The input. A Field Generation template for Case is anchored to a Case record. A Flex template lets you declare several inputs of your own, for example an Account record and a free-text question.
- The available resources. Merge fields, Flow resources, and Apex resources are offered according to the type. A Flow or Apex resource that a template can use must be built for that type.
- The place it can be launched. Some types appear on record pages or in the email composer. Others are called from Flow, Apex, or an agent.
You cannot freely change the type after you create a template, so decide before you write the body. If you choose wrong, create a new template and copy the text across.
The type as a contract with Apex
The Apex example in this tutorial's plan shows the link between type and code. An invocable method declares which template type it serves with the capabilityType attribute:
@InvocableMethod(
label='Get open tasks for case'
capabilityType='PromptTemplateType://einstein_gpt__fieldCompletion'
)The value einstein_gpt__fieldCompletion identifies the Field Generation type. Only templates of that type will list this method as an available resource. If you tag a method for one type and then look for it in a template of another type, it will not appear. A missing resource is, in practice, the most common symptom of a type mismatch. The Apex chapter works through the full class.
A first template
The simplest useful template is a summary of a Case. Here is a body for a Record Summary or Field Generation template whose input is a Case:
You are a support assistant. Summarize the case below in two sentences for an agent taking over.
Case subject: {!$Input:Case.Subject}
Status: {!$Input:Case.Status}
Priority: {!$Input:Case.Priority}
Description: {!$Input:Case.Description}
If a value above is empty, say it is not provided. Do not guess.Read it in three layers:
- Role and task. "You are a support assistant. Summarize..." tells the model who it is and what to produce.
- Grounding data. The four lines with
{!$Input:Case...}are merge fields. Each is replaced by a value from the input Case. - Rules for gaps. The last line says what to do when data is missing.
When the template resolves for a case with the subject "Printer offline", status "Working", priority "High", and a filled description, the model sees those literal values, not the placeholders. The model never sees the merge field syntax and never queries Salesforce itself. It only reads the final text. This matters later: if your data is not in the resolved text, the model cannot use it.
The syntax is a pattern you will see often: {! opens a placeholder, $Input says the value comes from the template's input, Case names the input, and .Subject names the field. Resources use other prefixes, such as $Flow for a Flow resource, shown below.
Recent order history:
{!$Flow:Get_Recent_Orders.Prompt}Grounding sources at a glance
A template can draw its data from three kinds of source. This chapter only introduces them so you recognize the syntax when later chapters build each one.
| Source | Example placeholder | Best for |
|---|---|---|
| Record merge fields | `{!$Input:Case.Subject}` | Fields on the input record |
| Relationship fields | `{!$Input:Case.Account.Name}` | Fields on a parent record |
| Flow resource | `{!$Flow:Get_Recent_Orders.Prompt}` | Data that needs queries or logic |
| Apex resource | An Apex method chosen in the editor | Cases a Flow cannot handle |
Versions and activation
A template does not take effect until a version is active. This is a deliberate safeguard.
- You edit a version in draft state, preview it, then activate it.
- Only one version of a template is active at a time.
- Activating a new version replaces the old one wherever the template is used. Users on record pages get the new behavior without any change to the page.
- Older versions stay in the list, so you can roll back by activating one again.
Treat each activation like a release. Change the wording, preview against several records, and only then activate. A prompt edit can change output across every record that uses the template.
Common errors with templates and types
Most early problems come from a small set of mistakes.
- Wrong type chosen. The template cannot be placed where you want it, or your Flow or Apex resource does not appear. Fix by creating a new template of the right type.
- Resource tagged for a different type. The Apex
capabilityTypeor the Flow's configuration does not match the template type, so the resource is not offered. - Placeholder typed incorrectly. A misspelled field or object name leaves the placeholder unresolved or causes an error. Use the Insert Resource control to avoid typos.
- Template not activated. Users still see the old behavior, or no template at all, because the new version is still a draft.
- Missing access. A user without access to the template or to the underlying fields gets an error or an empty value. Chapter 11 covers permissions and limits.
- Assuming the model can look things up. Anything not in the resolved text does not exist for the model. If a fact matters, ground it.
How this chapter fits the rest
The type and the input decide what you can ground. The following chapters build on that order:
- Template inputs, which define the record behind the prompt.
- Record merge fields and related-record fields.
- Flow and Apex resources for data that merge fields cannot reach.
- Choosing among them, then previewing and testing.
- Permissions, data quality, and size limits.
Exercise
A teammate writes an invocable Apex method with capabilityType='PromptTemplateType://einstein_gpt__fieldCompletion'. In Prompt Builder, they open a Sales Email template and cannot find the method in the resource list. What is the most likely cause, and what are two ways to fix it?
Show answer
The method is tagged for the Field Generation type, and a Sales Email template only lists resources built for its own type. One fix is to create a Field Generation template and use the method there. The other is to change the method's capabilityType to the type that matches a Sales Email template, then deploy it. Check the current Salesforce documentation for the correct type identifier.
Exercise
The model's summary of a Case ignores the customer's recent orders, even though the orders exist in Salesforce. The template body contains only {!$Input:Case.Subject} and {!$Input:Case.Description}. Why does the model ignore the orders, and what do you add?
Show answer
The model sees only the resolved prompt text, and the orders are not in it. Nothing in the template fetches them. Add a resource that returns the order data, such as a Flow resource placed in the body with {!$Flow:Get_Recent_Orders.Prompt}, and tell the model how to use it.
Exercise
You edit the active version of a template to change its tone and save it as a new version. Users still see the old tone on their record pages. What step did you skip?
Show answer
You did not activate the new version. Only the active version is used, so the draft version has no effect until you preview it and activate it.