Skip to main content
Estimación de tiempo

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 Copilot, 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, 14-day custom playground that contains Einstein AI and our sample data.

  1. If you haven't already, click the I can receive a password email checkbox in the beginning of the unit.
  2. Click Create Playground.
  3. Follow the prompts.
Note

This custom playground is designed to work with the challenges in this badge and may not work for other badges. Always check that you’re using the Trailhead Playground or special org that we recommend.

If you’re working on the Drive Productivity with Einstein AI Trail, you’ll also use this org for these Trailhead projects:

Add Experience Data

Before you get started with Prompt Builder, let’s create two new resort events to use as test data.

  1. In your custom playground, click the App Launcher App Launcher icon and enter Experience in the search bar. Click Experiences.
  2. Click New.
  3. For Experience Name, enter Family Karaoke Night.
  4. Select Low in the Activity Level field.
  5. Enter 50 in the Capacity field.
  6. For Default Start Time, select 6:00 PM.
  7. 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.
  1. Type 2 for the Duration.
  2. Type Melody Lounge in the Location Field.
  3. Select Family & Kids’ Activities from the Type dropdown menu.
  4. Click Save & New.
  5. Enter Sunrise Yoga in the Experience Name field.
  6. Select Medium in the Activity Level Field.
  7. Enter 35 in the Capacity field.
  8. For Default Start Time, select 7:00 AM.
  9. 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!
  1. Type 1 for the Duration.
  2. Type Cocoa Shore in the Location field.
  3. Select Fitness & Exercise from the Type dropdown menu.
  4. 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.

  1. Click gear icon and click Setup.
  2. In the Quick Find box, enter Einstein Setup and click Einstein Setup.
  3. Toggle the Turn on Einstein switch to On, and refresh your screen. (Skip these steps if you’ve already enabled Einstein in the playground.)
  4. Click gear icon and click Setup.
  5. In the Quick Find box, enter prompt, then click Prompt Builder.
  6. Click New Prompt Template.
  7. 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.
  8. 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
  9. To add the second one, click Add Resources, then enter:
    • Name: Experience
    • API Name: Experience
    • Source Type: Object
    • Object: Experience
  10. 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.

Resources Picklist displaying the list of resources. Flows, Apex, Current Organization, Current User, Reservation, Experience

  1. 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.
  2. Find the text {Check-in Date} in the prompt and delete it.
    • In the Resource field, select Reservation > Check-in Date.
  3. Find the text {Check-out Date} in the prompt and delete it.
    • In the Resource field, select Reservation > Check-out Date.
  4. Find the text {Room Type} in the prompt and delete it.
    • In the Resource field, select Reservation > Room Type.
  5. Find the text {Experience Name} in the prompt and delete it.
    • In the Resource field, select Experience > Experience Name.
  6. Find the text {Experience Location} in the prompt and delete it.
    • In the Resource field, select Experience > Location.
  7. Find the text {Experience Details} in the prompt and delete it.
    • In the Resource field, select Experience > Description.
  8. Under Models, select OpenAI GPT 4.
  9. Click Save.

Your prompt template should look like the following.

Flex prompt template with the merge fields correctly added.

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.

  1. In the Reservation field type, er. Select any reservation.
  2. In the Experience field type, Sun. Select Sunrise Yoga.
  3. 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.

Comparta sus comentarios sobre Trailhead en la Ayuda de Salesforce.

Nos encantaría conocer su experiencia con Trailhead. Ahora puede acceder al nuevo formulario de comentarios cuando quiera desde el sitio de la Ayuda de Salesforce.

Más información Continuar para compartir comentarios