Skip to main content
Join Trailblazers for Dreamforce 2024 in San Francisco or on Salesforce+ from September 17-19. Register now

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 (“Einstein button icon”) 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.

Case details displaying Case AI Summary field and Einstein button.

To configure the Einstein button and generate the LLM response, Linda needs two things.

  1. A field generation prompt template created with Prompt Builder.
  2. 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:

  1. Prompt Template Type: Field Generation
  2. Prompt Template Name: Case Comments Summary
  3. API Name: Case_Comments_Summary
  4. Template Description: Summary of case details.
  5. Object: Case
  6. 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.

Lightning App Builder view adding the Case AI Summary field to Case Information.

  • 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.

Lightning App Builder field properties panel for the Case AI Summary 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.

Select Type window with Template-Triggered Prompt Flow selected.

After Flow Builder loads, Linda enters this information in the Start panel.

  1. 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.
  2. Object: Case

The Start element’s configuration panel corresponding to the preceding instructions.

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.

  1. Label: Get Case Comments
  2. Object: Case Comment
  3. Field: ParentId
  4. Operator: Equals
  5. Value: select $Input then RelatedEntity then Id
  6. How Many Records to Store: All records

The Get Records element’s configuration panel corresponding to the preceding instructions.

Linda wants the case summary to specify when the case has no comments, so she adds a Decision element after the Get Records element.

  1. Label: Comments Found?
  2. First Outcome Details:
    1. Label: Yes
    2. Resource: Case Comments from Get Case Comments
    3. Operator: Is Empty
    4. Value: False
  3. 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.

The Decision element’s configuration corresponding to the preceding instructions.

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.

  1. Label: Loop Comments
  2. Collection Variable: Case Comments from Get Case Comments
  3. 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.

  1. Label: Send Comments to Prompt
  2. Prompt Instructions: Enter “Summarize the case's comments using”.
  3. 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.

The Send Comments to Prompt element’s configuration panel corresponding to the preceding instructions.

On the No path, Linda adds another Add Prompt Instructions element. This element tells the prompt template that no comments were found.

  1. Label: No Comments for Prompt
  2. Prompt Instructions: The case has no comments to summarize.

Linda’s flow now looks like this.

The complete Get Case Summary flow for use in field generation prompt templates.

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.

Resource picker selected with Flows option displayed.

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.

  1. Prompt Template Type: Flex
  2. Prompt Template Name: Product Details
  3. API Name: Product_Details
  4. Template Description: Information about product
  5. Define a resource for account information:
    • Name: Account Info
    • API Name: Account_Info
    • Object: Account
  6. Define a resource for asset information:
    • Name: Asset Info
    • API Name: Asset_Info
    • Object: Asset
  7. Define a resource for contact information:
    • Name: Contact Info
    • API Name: Contact_Info
    • Object: Contact

Write a detailed product description using this information:

The Account Name is {!$Input:Account_Info.Name}

The Product Info is {!$Input:Asset_Info.Description}

The Contact Info is {!$Input:Contact_Info.Name}

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.

Resources