Build a Field Generation Prompt Template
Learning Objectives
After completing this unit, you’ll be able to:
- Use Prompt Builder to create a field generation prompt template.
- Create a flow that sends data to a prompt template.
- Create a flex 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
- 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 without writing any code. In Flow Builder, Linda creates a Template-Triggered Prompt Flow for her Case Comments Summary prompt template. Flows with the Template-Triggered Prompt Flow type run only from a prompt template.
After Flow Builder loads, Linda enters this information in the Start panel.
- Select Input Type: Automatic Inputs
- Prompt Template Type: Field Generation Template Capability
Remember, when Linda created the prompt template, she selected the Prompt Template Type “Field Generation”. So here, she sets the Prompt Template Type to match.
- Object: Case
Linda wants the prompt to include all of the case’s comments, so she adds a Get Records element to retrieve and store them in a collection.
- Label:
Get Case Comments
- Object: Case Comment
- Field: ParentId
- Operator: Equals
- Value: select $Input then RelatedEntity then Id
- How Many Records to Store: All records
Linda wants the case summary to specify when the case has no comments, so she adds a Decision element after the Get Records element.
- Label:
Comments Found?
- First Outcome Details:
- Label:
Yes
- Resource: Case Comments from Get Case Comments
- Operator: Is Empty
- Value: False
- Label:
- Default Outcome Label:
No
This element splits the flow into two paths: one that the flow takes when comments are found on the current record, and one that it takes when no comments are found.
To send the collected comment data to the prompt for summarization, Linda uses the Add Prompt Instructions element. But this element can’t receive the comment data in its current form. The collection created by the Get Case Comments element contains all the data from the related Case Comment records. Linda wants only the comments, so the flow must first separate the comment text from the rest of each record. Additionally, the Add Prompt Instructions element must receive data one record at a time.
Loops are the perfect tool for this situation. A loop looks at a record, does something with that record, and repeats that process until it has processed all of the records in the collection. Linda adds a Loop element on the Yes path.
- Label:
Loop Comments
- Collection Variable: Case Comments from Get Case Comments
- Direction: First item to last item
Now Linda adds an Add Prompt Instruction element to the Yes path. Think of the Add Prompt Instruction element like a direct channel between your flow and the prompt. Everything in the element’s prompt instructions is merged directly into the prompt that ran the flow. For example, if the Add Prompt Instruction element’s Prompt Instructions field contained the formula “{!test}”, the prompt would add the result of that formula to the prompt template.
- Label:
Send Comments to Prompt
- Prompt Instructions: Enter “
Summarize the case's comments using
”.
- Click in the Insert a resource field, then select Current Item from Loop Loop_Comments, and then select CommentBody.
This resource merges the current case comment’s text into the prompt instructions.
On the No path, Linda adds another Add Prompt Instructions element. This element tells the prompt template that no comments were found.
- Label:
No Comments for Prompt
- Prompt Instructions:
The case has no comments to summarize.
Linda’s flow now looks like this.
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 category. When she selects Flows, she sees her new template-triggered prompt flow, Get Case Summary.
She selects Get Case Summary, 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} """ |
---|
Now Linda’s 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 a resource for account information:
- Name:
Account Info
- API Name:
Account_Info
- Object: Account
- Name:
- Define a resource for asset information:
- Name:
Asset Info
- API Name:
Asset_Info
- Object: Asset
- Name:
- Define a resource for contact information:
- Name:
Contact Info
- API Name:
Contact_Info
- Object: Contact
- Name:
Write a detailed product description using this 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.