Create and Ground Prompt Templates
Learning Objectives
After completing this unit, you’ll be able to:
- Describe what grounding is.
- Explain how to use Prompt Builder to create a prompt template.
- Summarize the benefits of using Flow and Data Cloud with prompt templates.
- Explain how to add resources to prompt templates.
The Why and the How
In the Prompt Builder: Quick Look module, Linda Rosenberg, a Salesforce admin, aimed to reduce her sales team's manual workload by automating tasks with prompt templates. In this module, we take a deeper dive and show you why and how she did it.
Build a Sales Email Prompt Template
Linda needs to create a template that her sales team can use to generate emails. She wants to reduce the time that the team spends on creating invitations to customers for product events.
To do this, Linda navigates to Prompt Builder in Salesforce Setup. When she navigates to Prompt Builder, the first page that’s shown is the Prompt Builder Explore page. Here you’ll find:
- Guidance to help you learn more about the features of Prompt Builder.
- Access to prompt template walkthroughs and examples.
- A listing of all existing prompt templates with their type, category and status.
- Functionality to edit and delete existing prompt templates.
From the Explore page, Linda can also create a prompt template. She clicks the New Prompt Template button.
Linda starts to complete the fields in the template type setup screen.
When you set up a prompt template, it’s important to have a clear goal. In this case, Linda must think about who her company’s customers are and what the sales team wants them to see in the email.
Linda understands that her email may be sent to any Cloud Kicks contact. Therefore, Contact is the recipient object. She completes the template type setup by selecting:
- Prompt Template Type: Sales Email
- Prompt Template Name:
Invite Customer to Local Product Event
- API Name:
Invite_Customer_to_Local_Product_Event
- Template Description:
Email customer to invite to local product event.
- Recipient: Contact
- Related Object: Account
Ground Your Template
You learned that making templates specific makes them effective. Another way of saying “specific” is to say your template is grounded.
Once Linda has defined her template type, she begins drafting and grounding her prompt in the Template Workspace.
Linda includes the customer name, who the email is from, their titles, and details about the event.
You are a Salesforce admin and your name is Linda Rosenberg from the organization Cloud Kicks. Your prospect is Rob Hutchinson, a director from Acme Inc., and they are based in Toronto, Ontario. In the email, invite the prospect to attend the event “Floating on Clouds: Toronto Kickoff” on September 18, an event for customers of Cloud Kicks new and old to network and preview upcoming products, in no more than 70 words. Explain to the prospect the possible benefits of attending the event and mention that you would be happy to chat with them further at the event or online if they need more information. |
---|
The prompt looks great. However, her first draft is hard-coded for only one specific sender and recipient. That would be okay if the prompt is going to be used once. But the concept of a prompt template is that it can be used for any sender and recipient. What she needs is a way to get her company’s CRM data into the template and ground it automatically.
Happily, Linda knows that she can use merge fields, Apex, and Flow as resources to enable Prompt Builder to securely access Salesforce data.
Add Merge Fields to a Prompt Template
Linda reviews her prompt and looks for areas where she can use merge fields to take her prompt from hardcoded for one-time use to reusable for any sender and recipient.
You are a Salesforce admin and your name is Linda Rosenberg from the organization Cloud Kicks. Your prospect is Rob Hutchinson, a director. They are based in Toronto, Ontario. In the email, invite the prospect to attend the event “Floating on Clouds: Toronto Kickoff” on September 18, an event for customers of Cloud Kicks new and old to network and preview upcoming products, in no more than 70 words. Explain to the prospect the possible benefits of attending the event and mention that you would be happy to chat with them further at the event or online if they need more information. |
---|
Within the Prompt Template Workspace, Linda uses the Resource picklist to choose the type of resource to use. She sees there are multiple options for sales email prompt templates. Current Organization, Sender, and Recipient are all available to use in her prompt template.
In the Resources picklist, Linda selects Sender and Recipient, where she then selects specific information, like title, name, company, and so on to ground her prompt template. She saves her work.
You are a In the email, invite the prospect to attend the event "Floating on Clouds: Toronto Kickoff" on September 18, an event for customers of Cloud Kicks new and old to network and preview upcoming products, in no more than 70 words. Explain to the prospect the possible benefits of attending the event and mention that you would be happy to chat with them further at the event or online if they need more information. |
---|
After she’s done, she notices there’s one piece of her prompt that needs an adjustment before it can display the correct response: "Floating on Clouds: Toronto Kickoff" on September 18.
At Cloud Kicks, “Floating on Clouds” is a nationwide event that hosts local customers based on their city. Linda wants to make sure the sales email prompt template is as personalized as possible and generates emails that invite customers to local events.
Linda understands that using only merge fields for this portion isn't enough. She needs logic incorporated into her prompt template. There are several approaches to accomplish this within Prompt Builder, including using Apex or Template-Triggered Prompt Flows. First, let’s explore how to use Apex in prompt templates.
Add Apex to a Prompt Template
If you want to use data from a SOQL query or an external API in your prompt, consider Apex. Apex is also effective if you want to generate well-formatted JSON or do programmatic data filtering.
In this case, Linda wants to create an Apex class that finds events that are close to a given contact and returns the name of the events, subject, location, and start time. Using the Developer Console she creates a class named ContactEventsPrompt
with a method annotated as InvocableMethod
. The InvocableMethod
must accept List<Request>
where the inputs defined in the Request
class match the inputs within the prompt. Also, the InvocableMethod
must be labeled with the CapabilityType
that matches the template type.
Once her class is created, Linda returns to the Prompt Template Workspace in Prompt Builder and notices that Apex is now a resource. She adds the Apex class by clicking Resource and selecting Apex.
You’re a In the email, invite the prospect to attend an event for customers of Cloud Kicks new and old to network and preview upcoming products, in no more than 70 words.Explain to the prospect the possible benefits of attending the event and mention that you would be happy to chat with them further at the event or online if they need more information. Add the following event information to the email: |
---|
Great! Now instead of referencing one single event. Linda can rely on her Apex class to return an event close to the specified contact.
Build a Field Generation Prompt Template
Field Generation prompt templates have a direct relationship to record fields. With the help of Lightning App Builder (LAB), an Einstein button () can trigger an assigned prompt template to send a prompt to the LLM and return a response back to the specific field.
Linda wants to help customer support agents quickly come up to speed to help any Cloud Kicks customer. She'll utilize a field generation prompt template to generate a summary of the related case comment history when the agent clicks the Einstein button for a case summary field.
To configure the Einstein button and generate the LLM response, Linda needs two things:
- A field generation prompt template created with Prompt Builder.
- A field added to a component and configured in LAB.
Create a Field Generation Prompt Template
Linda opens Prompt Builder and creates a new prompt template. She selects her prompt template type, and completes the template setup by selecting:
- Prompt Template Type: Field Generation Template Capability
- Prompt Template Name:
Case Comments Summary
- API Name:
Case_Comments_Summary
- Template Description:
Summary of case details.
- Object: Case
- Object Field: Case_AI_Summary__c
After the prompt template setup is complete, she creates her prompt template in the Template Workspace.
You are a support representative who is tasked with creating a short summary of a case that happened between a customer and a company support rep. |
---|
She clicks Save and Activate to access the template within LAB. Now that Linda has a ready-to-use prompt template, she needs to create a Case AI Summary field on the Case record page.
Configure a Field in LAB to Connect Field Generation Prompt Templates
To use an Einstein button to trigger a field generation prompt template in a record, Linda must configure the field in LAB. To start, she can select an existing Lightning Record page or create a new one.
Linda can drag either a Record Detail component or a Field Section component onto the selected page.
-
For a Field Section component: Linda can drag a form field onto the Field Section component.
-
For a Record Detail component: Linda must migrate the component to Dynamic Forms. She can do this migration by selecting Upgrade from the right-hand panel and following the steps in the upgrade wizard. This change allows her to configure fields from her existing record pages as individual components.
Linda can select any form field that supports field generation, including writable text, text area, text area (long), and text area (rich) field types. Field generation prompts aren't compatible with read-only fields.
In the Einstein Generative AI section of the Field Properties panel, she selects a Field Generation prompt template to assign to the form field.
Linda then saves and activates the record page.
Linda understands she needs to incorporate real-time data into her prompt template to make it relevant. This can be invoked from a flow.
Add a Flow to a Prompt Template
With the help of Flow Builder, admins can create Template-Triggered Prompt Flows to incorporate complex logic in prompt templates. In Flow Builder, Linda creates a Template-Triggered Prompt Flow for her Field Generation Prompt Template.
She creates the following flow:
- Template-Triggered Prompt Flow Name:
Get Case Summary
- Prompt Template Type Capability: Field Generation Template Capability
- Object: Case
When she saves and activates the Flow, it’s immediately available in Prompt Builder to use for any Field Generation prompt template whose object is Case.
After Linda activates her flow in Flow Builder, she navigates to the Resources list in the Prompt Templates Workspace and notices that Flows is now a resource. When she selects Flows, she sees her new Template-Triggered Prompt Flow,Get_Case_Summary
.
She selects it, and her new flow is inserted into the prompt template as {!$Flow:Get_Case_Summary.Prompt}
.
You are a support representative who is tasked with creating a short summary of a case that happened between a customer and a company support rep. """ Case Data: {!$Flow:Get_Case_Summary.Prompt}
""" |
---|
Linda’s now ready to test her prompt template to see the results.
Build a Flex Prompt Template
So far we’ve covered Sales Email and Field Generation prompt templates. However, if your specific use case doesn't align with those templates, Prompt Builder offers flexibility for all scenarios. Unlike other prompt templates, Flex template inputs aren’t predefined; instead, you choose them during template creation. In Prompt Builder, you have the option to add up to five inputs to a Flex template. Once defined, the resource picker shows these inputs, and your prompt template can reference them using merge fields.
Linda wants to use Prompt Builder to create a product description using the account name, asset details, and contact information. Since the Field Generation prompt template doesn't offer the necessary input choices in terms of quantity (three) and type (account, asset, and contact) for her needs, she decides to create a Flex prompt template. Linda completes the setup and creates her prompt template.
- Prompt Template Type: Flex
- Prompt Template Name:
Product Details
- API Name:
Product_Details
- Template Description:
Information about product
- Define Resources:
Name |
API Name |
Object |
---|---|---|
Account Info
|
Account_Info
|
Account |
Asset Info
|
Asset_Info
|
Asset |
Contact Info
|
Contact_Info
|
Contact |
Write a detailed product description using the following information: The Account Name is The Product Info is The Contact Info is |
---|
Well done. You’ve learned that Prompt Builder is flexible enough to accommodate your everyday business needs. Whether you choose to use a flow or create an Apex class, Prompt Builder helps minimize the time spent on your daily tasks.