Build a Flex Prompt Template
Learning Objectives
In this project, you’ll:
- Create a Flex prompt template using Prompt Builder.
- Create a Template-Triggered Prompt Flow to use in a Flex prompt template.
Before You Start
Before you start this module, consider completing the following recommended content.
Introduction
Flex prompt templates in Prompt Builder offer a versatile and efficient way to automate the creation of text for PDFs, social media posts, newsletters, emails, record fields, and more with Einstein generative AI and the LLM (large language model). Unlike the Sales Email or Field Generation prompt templates in Prompt Builder, Flex templates don’t have predefined entry points. What does this mean? You can select any object in your organization to use in the template and apply the completed prompt wherever you see fit. Whether you're using Apex, Flow, REST API, or Agentforce, Flex templates are designed to fit your needs.
In this project, you learn how to create and test a Flex prompt template in Prompt Builder. You also discover how to use a flow to improve prompt responses and handle large data sets effectively. Your task is to design a newsletter for a popular vacation destination, Coral Cloud Resort, highlighting the events happening on the property during the guests’ stay.
Sign Up for a Custom Playground with Einstein AI
To complete this project, you need a special, limited-time custom playground that contains Einstein AI and our sample data.
- If you haven't already, click the I can receive a password email checkbox in the beginning of the unit.
- Click Create Playground.
- Follow the prompts.
- Make note of your org's expiration date and complete this badge before then.
Add Experience Data
Before you get started with Prompt Builder, let’s create two new resort events to use as test data.
- In your custom playground, click the App Launcher and enter
Experience
in the search bar. Click Experiences.
- Click New.
- For Experience Name, enter
Family Karaoke Night
.
- Select Low in the Activity Level field.
- Enter
50
in the Capacity field.
- For Default Start Time, select 6:00 PM.
- Paste the following text in the Description field:
Join us for Family Karaoke Night and sing your heart out with your loved ones! It's a fun-filled evening where you can showcase your talent, laugh together, and create unforgettable memories.
- Type
2
for the Duration.
- Type
Melody Lounge
in the Location Field.
- Select Family & Kids’ Activities from the Type dropdown menu.
- Click Save & New.
- Enter
Sunrise Yoga
in the Experience Name field.
- Select Medium in the Activity Level Field.
- Enter
35
in the Capacity field.
- For Default Start Time, select 7:00 AM.
-
Paste the following text in the Description field:
Start your day with Sunrise Yoga on the beach, where you can stretch under the warm morning sun and listen to the soothing sound of the waves. It's the perfect way to feel refreshed and ready for a fun day ahead!
- Type
1
for the Duration.
- Type
Cocoa Shore
in the Location field.
- Select Fitness & Exercise from the Type dropdown menu.
- Click Save.
Create a Flex Template
With the data ready, it’s time to create a new Flex prompt template. This step establishes the foundation for your prompt. As you set up Flex templates in your own projects, choose your API names carefully because they will be used in templates that use Apex or Flow.
- Click and click Setup.
- In the Quick Find box, enter
Einstein Setup
and click Einstein Setup.
- Toggle the Turn on Einstein switch to On, and refresh your screen. (Skip these steps if you’ve already enabled Einstein in the playground.)
- Click and click Setup.
- In the Quick Find box, enter
prompt
, then click Prompt Builder.
- Click New Prompt Template.
- Complete the template setup by selecting:
- Prompt Template Type: Flex
- Prompt Template Name:
New Guest Newsletter
- API Name:
New_Guest_Newsletter
- Template Description:
Newsletter for incoming resort guests.
- Prompt Template Type: Flex
- For Flex templates, you can add up to five resources. Under Define Sources, add two resources with the object type. For the first one, enter:
- Name:
Reservation
- API Name:
Reservation
- Source Type: Object
- Object:
External Reservation
- Name:
- To add the second one, click Add Resources, then enter:
- Name:
Experience
- API Name:
Experience
- Source Type: Object
- Object:
Experience
- Name:
- Click Next. You’re redirected to the Prompt Template Workspace.
Create a Prompt
Excellent. For this scenario, we’ve provided a prompt to help get you started with creating the resort newsletter. You’ll notice it includes merge fields for the guest reservation information and the resort experience details. If you’re interested in learning about what makes a great prompt, check out the Prompt Fundamentals badge.
Paste the following text into the Prompt Template Workspace:
You're the Director of Fun at Coral Cloud Resort writing a newsletter to welcome {the new guest} and inform them of upcoming activities during their stay. The purpose of the newsletter is to get guests excited about staying at the resort. When I ask you to create the newsletter, you must strictly follow my instructions below. Instructions: """ Introduce the resort in a newsletter no longer than three paragraphs. Inform the guests about their reservation using the following details: Check In: {Check-in Date} Check Out: {Check-out Date} Room Selection: {Room Type} Include a bulleted list of the experiences available during guests stay, including the description and the locations. The experiences are as follows: Experience Name: {Experience Name} Experience Location: {Experience Location} Experience Details: {Experience Details} Use clear and straightforward language using the active voice and strictly avoiding the use of filler words and phrases and redundant language. Be conversational. Do not attribute any negative traits in the summary. End with a call to action for readers to look at our website for these offers. """ Now create the newsletter.
Add Merge Fields
Within your new prompt, the merge fields–the text enclosed in curly braces–add context. In Prompt Builder, you can easily incorporate relevant data from CRM, Data Cloud, or external sources (via Data Cloud) by selecting the resource from the Resource picklist. You do that next.
- Find the text {the new guest} in the prompt and delete it. Then replace that text with the correct merge field, by:
- Clicking in the Resource field, and selecting Reservation > External Guest > First Name.
- Clicking in the Resource field, and selecting Reservation > External Guest > First Name.
- Find the text {Check-in Date} in the prompt and delete it.
- In the Resource field, select Reservation > Check-in Date.
- In the Resource field, select Reservation > Check-in Date.
- Find the text {Check-out Date} in the prompt and delete it.
- In the Resource field, select Reservation > Check-out Date.
- In the Resource field, select Reservation > Check-out Date.
- Find the text {Room Type} in the prompt and delete it.
- In the Resource field, select Reservation > Room Type.
- In the Resource field, select Reservation > Room Type.
- Find the text {Experience Name} in the prompt and delete it.
- In the Resource field, select Experience > Experience Name.
- In the Resource field, select Experience > Experience Name.
- Find the text {Experience Location} in the prompt and delete it.
- In the Resource field, select Experience > Location.
- In the Resource field, select Experience > Location.
- Find the text {Experience Details} in the prompt and delete it.
- In the Resource field, select Experience > Description.
- In the Resource field, select Experience > Description.
- Under Models, select OpenAI GPT 4.
- Click Save.
Your prompt template should look like the following.
Great work! Your prompt template is now complete and ready to be tested.
Test the Prompt
In the Preview window there are two fields for test data, Experience and Reservation. Here, you can select test data to provide your prompt template to see what a generated response would look like.
- In the Reservation field type,
er
. Select any reservation.
- In the Experience field type,
Sun
. SelectSunrise Yoga
.
- Click Preview. Take a look at the output of your prompt template.
In the Response section, you can see how the Reservation and Experience data personalizes the newsletter for your guest. However, there are multiple events that happen at the resort. You want the newsletter to share more than just one event. In the next step, learn how to use flows to add additional content–in this case, additional guest experiences.