Sub topic 3
Choosing a prompt template type
This chapter assumes you know the basic Salesforce data model (objects, fields, records) and can work in Setup. It also assumes you know what an Agentforce agent and a topic are. The previous chapter introduced Prompt Builder and what a prompt template is. This chapter covers the decision you make when you create one: which template type to pick.
Why the type matters
Every prompt template in Prompt Builder has a type. The type is fixed when you create the template, and you can't change it afterward. It controls three things:
- Which inputs the template accepts. Some types take one record of a fixed object. Others take any mix of records and text.
- Where the output can be used. Some types are built to write into a record field or a record page. Others return text to a caller.
- Which merge fields and resources are available in the editor.
For an agent action, the type decides whether the template can take the inputs your topic can supply. Picking the wrong type means recreating the template. You can copy the prompt text, but you can't convert the template.
The four common types
Prompt Builder offers these types. The list can change between releases, so check the type picker in your org.
| Type | Typical input | Typical output location | Best for |
|---|---|---|---|
| Sales Email | A recipient (contact or lead), a sender, optionally a related record | An email draft in the email composer | Personalized outreach and follow-up emails |
| Field Generation | One record of one object | A long-text field on that record | Filling a field, such as a description or a recommended next step |
| Record Summary | One record of one object | A summary shown on the record page | Short overviews of a record and its related data |
| Flex | Any combination of records, free text, and resources | Text returned to whatever called it | General-purpose generation, including agent actions, Flow, and Apex |
Sales Email
A Sales Email template produces an email body for a person. Its inputs are shaped around that job: a recipient, a sender, and optionally a related record such as an opportunity. The output is meant to land in the email composer, where a human reviews it before sending. Use it when the result is an email and a person is in the loop.
Field Generation
A Field Generation template is bound to one object. You then place its output into a field on that object, usually a long-text field. The input is always the single record being edited. Use it when the generated text belongs in the record permanently, for example a "Customer Summary" field that users can click to generate or refresh.
Record Summary
A Record Summary template also takes one record, but the result is displayed on the record page and isn't stored in a field. Use it when users want a quick overview and you don't want to keep the text on the record.
Flex
A Flex template is the general-purpose type. You decide the inputs. You can declare a Case record, a Contact record, and a free-text input in the same template. The output isn't tied to a field or a page. It is returned to the caller.
That last property is why Flex matters in this tutorial. An agent action needs a template that can receive inputs from the agent's conversation and hand text back to the agent. A Flex template has no built-in output location, so the agent, a Flow, or Apex can each use it. The other types are built around one fixed record and one fixed surface, and that makes them a poorer fit when the input comes from a conversation.
A decision path
Ask these questions in order.
- Is the output an email that a person reviews before sending? If yes, use Sales Email.
- Does the text belong in a field on a record? If yes, use Field Generation.
- Is it a display-only overview of a single record on its page? If yes, use Record Summary.
- Does an agent, a Flow, or Apex need to call it, or does it need inputs beyond one record? If yes, use Flex.
If both rules apply, choose Flex. For example, you might want a summary on the Case page and also want an agent to return the same summary in a conversation. The agent requirement decides it.
A Flex template with several inputs
The strength of Flex is multiple, mixed inputs. The template below takes a Case record and a free-text input. It could back an agent action that answers a specific question about a case.
You are a service assistant. Answer the question below using only the case data.
Case number: {!$Input:Case.CaseNumber}
Subject: {!$Input:Case.Subject}
Status: {!$Input:Case.Status}
Description: {!$Input:Case.Description}
Question: {!$Input:CustomerQuestion}
Rules:
- Use at most three sentences.
- If the case data does not answer the question, say so.
- Do not promise refunds or dates.When you create a Flex template, you add each input in the template setup: one of type record (object Case) and one of type free text (named CustomerQuestion). The merge field names must match the input names you declared. Chapter four covers inputs and merge fields in detail. For now, notice that a Field Generation or Record Summary template can't accept the free-text input at all. This is the practical difference between the types.
What the type does not change
Some things stay the same across types, and mixing them up leads to wrong choices.
- The Trust Layer applies to all types. Masking of sensitive data and the other protections are not a feature of Flex only.
- Model selection is separate. You choose a model for the template, independent of its type. A type doesn't imply a model.
- Permissions still apply. The running user needs access to the records the template reads. A correct type with an inaccessible record still produces thin or empty output.
- Prompt quality is your job. A Flex template with vague instructions gives vague text. The type only gives you the inputs and the output channel.
Common mistakes
- Choosing Record Summary for an agent, because the use case says "summarize". The word describes the task, not the surface. If the agent must call it with a case number from a conversation, you need Flex.
- Building one Flex template for every purpose. A template that handles five jobs with conditional prompt text is hard to test and hard to version. Make separate templates, each with a narrow purpose and clear rules.
- Using Field Generation when the text should not persist. A field keeps the text until someone refreshes it. If the content is time-sensitive, such as a live status summary, a stored value goes stale. Prefer a Record Summary or a Flex template that is called when needed.
- Duplicating prompt text across types. If a Case summary is needed on the page and in an agent, two templates will drift apart over time. Decide which is the source of truth, and consider a single Flex template used by both paths through Flow or Apex, as covered in a later chapter.
- Forgetting that a type can't be changed. If you start with the wrong type, clone the text into a new template of the right type and retire the old one.
Quick comparison for agent design
For an agent action, three questions about your use case point to the right type:
- Where do the inputs come from? If the agent collects them from the conversation, you need a type that accepts free text or a record chosen at run time. That means Flex.
- What happens to the output? If the agent returns it to the user, you need text returned to a caller. That also means Flex.
- Does the same text have to appear elsewhere? If yes, decide whether another template type is justified, or whether the other surface can call the Flex template.
Exercise
A team wants an agent to answer "What is the status of case 00012345?" by returning a short generated paragraph. A second team wants a generated "Next Step" to be saved in a long-text field on each Opportunity. Which template type fits each, and why?
Show answer
The agent use case needs a Flex template. The agent supplies the case number from the conversation, and the template must return text to the agent. The Opportunity use case fits Field Generation. The text belongs in a field on one record, and the template takes that single Opportunity as input.
Exercise
You built a Record Summary template for Cases and now want an agent to call it. What do you do, and what is the main reason?
Show answer
Create a new Flex template. A template's type can't be changed, and a Record Summary template is built around one record shown on a page. It can't take the inputs the agent collects in conversation or return text to the agent. Copy the prompt text into the Flex template, declare a Case input, and test it again. Then retire the old template if nothing else uses it.