Sub topic 2
Prompt templates and template types
This chapter assumes you know the basic Salesforce data model (objects, fields, relationships) and can find your way around Setup and permission sets. You should also know what a large language model prompt is. Flow and Apex come later, so you don't need them yet.
What a prompt template is
A prompt template is a saved prompt with placeholders. You write it in Prompt Builder, a tool in Setup. When the template runs, Salesforce replaces each placeholder with real data. It then sends the finished text to a large language model (LLM) and returns the response.
Grounding means supplying your own CRM data in the prompt so the model does not have to guess. The template is where grounding is defined. It holds two things:
- Instructions written in plain language, such as "Summarize the case in two sentences."
- Placeholders for data, written as merge fields such as
{!$Input:Case.Subject}. Later chapters cover them in detail.
You write the template once. Each time it runs, Salesforce resolves the placeholders for the record in question.
The resolution flow
The template you save is not what the model sees. Salesforce builds the prompt at run time.
When a result looks wrong, look at the resolved prompt first. The template and the data can each be correct on their own and still produce a bad prompt together.
Template types
Every template has a type, chosen when you create it. The type controls where the template can be used and what inputs it accepts.
| Template type | Typical use | Where it runs |
|---|---|---|
| Sales Email | Draft an email to a contact or lead | Email composer on a record |
| Field Generation | Fill a text field with generated content | A field on a record page |
| Record Summary | Summarize a record | Record page |
| Flex | General purpose, with several inputs of your choosing | Prompt Builder, flows, Apex, and other callers |
The first three types are tied to one object record, such as a Case or an Account. The record is the template's input, and its fields are available as merge fields. Flex templates are more open. You declare the inputs yourself, and they can be records or other values.
Pick the type from the job. If the output must land in a field on a Case page, use Field Generation. If you need to combine a Case with an unrelated Account and a free-text value, use Flex.
Available types and their names vary by release and by the Einstein features enabled in your org. Check what your org offers in Prompt Builder.
A first template
The following template uses the Case object. It is the same one the rest of the tutorial builds on.
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.It has three parts:
- A role and task: "You are a support assistant. Summarize..."
- Grounding data: the four lines that use
{!$Input:...}. - A rule for missing data: the last line.
If the Description field is empty, the resolved prompt contains an empty value after "Description:". The last instruction tells the model what to do in that case.
Type matters to later code
The type also appears in code. In a later chapter, an Apex method declares which template type it serves:
@InvocableMethod(
label='Get open tasks for case'
capabilityType='PromptTemplateType://einstein_gpt__fieldCompletion'
)The capabilityType value ties the method to templates of the Field Generation type. If it names a different type, the method will not be offered to your template. Remember this link between template type and resource. It explains many "why can't I see my Flow or Apex action?" problems.
Versions and models
A template can have more than one version. A version holds the instruction text and the model settings. Keep a working version active while you edit a new draft, so users are not affected by half-finished changes.
Prompt Builder lets you choose among the models your org has access to. The same template can give different wording on different models, so retest if you switch.
Common mistakes
- Wrong template type. The template can't be placed where you want it, or a resource doesn't show up. Check the type first.
- Placeholder typos. A misspelled field name leaves the placeholder unresolved or empty. Preview the template to catch this.
- Saving without activating. A new version doesn't affect users until you activate it.
Exercise
A team wants a prompt that summarizes a Case and also uses an unrelated Account chosen by the user. Why might Flex be a better type than Record Summary?
Show answer
Record Summary is tied to a single record of one object. Flex lets you declare several inputs of your own, so you can pass both a Case and an Account.
Exercise
You wrote an Apex method with a capabilityType for Field Generation, but your Record Summary template cannot use it. What is the likely cause?
Show answer
The method's capabilityType names a different template type from the template. Resources are offered only to templates of the matching type.