Skip to main content

Get Hands-On with Prompts

Learning Objectives

After completing this unit, you’ll be able to:

  • Write prompts using advanced prompt engineering techniques.
  • Explain the benefits of advanced prompt engineering when compared to direct prompting.

Now that you’re thinking like a prompt engineer, you can create some prompts of your own. You’ll tackle a couple of use cases by starting with a direct or zero-shot prompt template, then editing your initial prompts to take advantage of advanced engineering techniques. By comparing the model’s outputs for each prompt, you should be able to see how a few simple changes can enhance each response.

You’ll want to follow along with the steps in this unit in order to pass the challenge at the end and earn the badge. Make sure that, after you’ve signed up for the Developer Org, you connect that org to Trailhead (instructions below), before checking the challenge and earning this badge.

Sign Up for a Developer Edition Org for Agentforce

To complete this module, you need a special Developer Edition org that has Agentforce enabled. Get the free Developer Edition and connect it to Trailhead now so you can complete the challenges in this badge. Note that this Developer Edition 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 Developer Edition org that we recommend.

  1. Sign up for a free Developer Edition org with Agentforce by clicking the link.
  2. Fill out the form.
    • For Email, enter an active email address.
    • For Username, enter a username that looks like an email address and is unique, but it doesn’t need to be a valid email account.
  3. After you fill out the form, click Sign me up. A confirmation message appears.
  4. When you receive the activation email (this might take a few minutes), open it and click Verify Account.
  5. Complete your registration by setting your password and challenge question.
  6. You’re logged in to your Developer Edition.

Now connect your new Developer Edition org to Trailhead.

  1. Make sure you’re logged in to your Trailhead account.
  2. In the Challenge section at the bottom of this page, click the playground name and then click Connect Org.
  3. On the login screen, enter the username (the username is listed in the email you just received) and password for the Developer Edition you just set up.
  4. On the Allow Access? screen, click Allow.
  5. On the Want to connect this org for hands-on challenges? screen, click Yes! Save it.

You’re redirected back to the challenge page and ready to use your new Developer Edition to earn this badge.

Set Up Agentforce

First, make sure Agentforce is enabled.

  1. Click Setup.
  2. In the Quick Find field, search for and select Einstein Setup.
  3. Make sure the Turn on Einstein toggle is set to On.
  4. Refresh your browser to reload Setup.
  5. In the Quick Find field, search for and select Agentforce Agents.
  6. Make sure the Agentforce toggle is set to On.

Create a Zero-Shot Prompt Template

  1. In the Quick Find field, search for and select Prompt Builder.
  2. Click New Prompt Template.
  3. Select and enter the required information into the prompt template as follows.
    • Prompt Template Type: Flex
    • Prompt Template Name: Generate Sample Email
    • API Name: Generate_Sample_Email (this auto-populates)
    • Template Description: Creates a basic email template.
  4. Under Define Sources, enter the following details:
    • Name: Customer Account
    • API Name: Customer_Account (this will auto-populate)
    • Source Type: Object
    • Object: Account
  5. Click Next.
    Next, let’s start with simple instructions for an event invitation email. We’ll give the agent some instructions, plus the details it needs to create the invitation.
  1. Enter the following zero-shot instruction by copying and pasting this text into the Prompt text area.

Write the introduction and body for a friendly and professional email from the Salesforce marketing
team inviting an example customer to attend an upcoming event. Include the event name, location, and
value of attending.


Event Details:
Name: Salesforce AI Launch Tour
Location: Chicago
Date: June 25
  1. Now, reference a specific customer account for the model to use data from. Above the Template Settings, click Preview Settings (“”).
  2. Under Inputs, in the Customer Account field, search for and select Burlington Textiles Corp of America.
  3. Click Save & Preview (“”), above Inputs, to generate and preview the response.
    You’ll see two fields with outputs: Resolved Prompt and Generated Response. The Resolved Prompt section shows the prompt with any placeholders resolved. You can view your completed sample email in the Generated Response field.

This zero-shot response returns a fairly generic email, but offers a starting point. Let’s see what we can do to make the tone and structure better by adding some examples for the model to learn from.

Edit the Prompt with Few-Shot Examples

Let’s add a couple of few-shot examples to guide the model more clearly.

  1. Click Prompt (””) to go back to your prompt.
  2. Replace the text in the Prompt area by copying and pasting the following text:

Write the introduction and body for a friendly and professional email from the Salesforce marketing
team inviting an example customer to attend an upcoming event. Include the event name, location,
and value of attending.


Replicate the following format, but make the email body more detailed and evocative:


Event Details:
Name: Salesforce AI Launch Tour
Location: Chicago
Date: June 25


Example 1:
Event: Salesforce AI Launch Tour
Location: Chicago
Customer: Jordan Manning
Company: FutureWorks Industries
Email:
Subject: You’re Invited to the Salesforce AI Launch Tour – Chicago
Hi Jordan,
We’re excited to invite you and your team at FutureWorks Industries to the Salesforce AI Launch Tour
in Chicago on June 25.
Write the introduction and body for a friendly and professional email from the Salesforce marketing
team inviting an example customer to attend an upcoming event. Include the event name, location, and
value of attending.


Replicate the following format and tone, but replace all names with placeholders. Expand on the email
copy to include at least three paragraphs while keeping the tone friendly and the content engaging.


Event Details:
Name: Salesforce AI Launch Tour
Location: Chicago
Date: June 25


Example 1:
Event: Salesforce AI Launch Tour
Location: Chicago
Customer: Jordan Manning
Company: FutureWorks Industries
Email:
Subject: You’re Invited to the Salesforce AI Launch Tour – Chicago
Hi Jordan,
We’re excited to invite you and your team at FutureWorks Industries to the Salesforce AI Launch Tour
in Chicago on June 25.
It’s a great chance to see how Salesforce AI can drive productivity and connect with peers in your
industry.
Hope to see you there!
– Your Salesforce Team


Example 2:
Event: Salesforce Customer Success Summit
Location: New York
Customer: Maya Jones
Company: NextStep Health


Subject: Let’s Meet at the Salesforce Customer Success Summit
Hi Maya,
We’d love to see you at our Customer Success Summit in New York on May 12.
NextStep Health has been doing incredible work, and this event is a great opportunity to explore
new tools to grow faster with Salesforce. We're excited to share the future and out latest innovations
with our fantastic customers.
Let us know if you can make it!
– Your Salesforce Team
  1. Click Save & Preview to generate and preview the response in the Generated Response field.
    You should now see an email that incorporates language and style from your examples.

By giving your agent some specific examples of the kinds of outputs you’re looking for, you’ve helped it generate better emails. And, if you compare our two prompts, you’ll see that even simple examples can make a difference, particularly when combined with prompt instructions for how to use them. Best of all, this technique and the others you’ve learned work across LLMs and prompt types.

Try a Chain-of-Thought Prompt

Now that you’ve seen how to improve a basic prompt, let’s try taking a zero-shot prompt and adding another type of advanced engineering: chain-of-thought prompting. To show how these techniques work even with outputs in different formats, we’ll try this one with an Einstein AI-Generated Search Answers prompt.

Create a new prompt template

  1. If you’re still in the prompt for the previous section, click the back arrow to go back to the Prompt Builder Setup page.
  2. Click New Prompt Template.
  3. Fill in the following fields:
    • Prompt Template Type: Einstein AI-Generated Search Answers
    • Prompt Template Name: Resort Package Names
      API Name: Resort_Package_Names (this auto-populates)
    • Template Description: Generates package names for Coral Cloud resort offerings based on the provided details.
  4. Click Next.

Define the Prompt Instructions

  1. Above the Template Settings, click Preview Settings (””).
  2. On the left side of the page, enter the following information under Inputs:
    • Query: Generate 5 Package names
    • Chunks (each on its own line):
      • private villas
      • beachside dining
      • family-friendly atmosphere
  3. In the Prompt area, paste this text:
You are a marketing assistant creating luxurious and appealing resort package names.
Based on the following details, generate 5 creative and enticing names for a resort
vacation package.


Resort details:


Coral Cloud Resorts offers private villas, beachside dining, and a family-friendly
atmosphere focused on luxurious comfort.
  1. Click Save and Preview to test the prompt.
  2. Review the generated package names in the Response section to see how your examples changed the output. You’ll see an answer with numbered names inside brackets that looks something like this:

{"answer":"1. Coral Cloud Escape Package \n2. Beachside Bliss Family Retreat \n3. Luxe Villa Getaway \n4. Serenity by the Sea Experience \n5. Private Paradise Family Adventure","sources":""}

Your response might look different, but if you’ve generated new package names, that’s a success!

Add Chain-of-Thought Instructions

Now, let’s edit the template to add chain-of-thought instructions.

  1. Click Prompt (””) to get back to your prompt.
  2. Replace the current prompt text by copying and pasting this text:
You are a marketing assistant creating luxurious and appealing resort package names.
Based on the following details, generate 5 creative and enticing names for a resort
vacation package.


Resort details:
Coral Cloud Resorts offers private villas, beachside dining, and a family-friendly
atmosphere focused on luxurious comfort. Make the names concise, elegant, and themed
to match the details. Avoid generic phrases like “Special Deal” or “Vacation Offer.”
Aim for names that evoke emotion and curiosity. Explain your thought process for each
package step-by-step.

You’re adding chain-of-thought logic to your prompt by including the phrase, “explain your thought process for each package step-by-step”. Because the LLM can understand context, you can include these instructions anywhere that makes sense.

  1. Keep your query and chunks the same.
  2. Click Save & Preview to generate the updated response.

Now you’ll see something along these lines:

{"answer":"1. **Serenity Shores Retreat** - This name conveys a sense of peace and tranquility, appealing to those seeking relaxation in luxurious surroundings.\n\n2. **Coral Haven Escape** - The use of 'Haven' suggests a safe and welcoming space, while 'Escape' evokes a desire to leave daily stress behind for a luxurious getaway.\n\n3. **Azure Bliss Villas** - 'Azure' reflects the beautiful ocean colors, and 'Bliss' communicates a feeling of happiness and contentment associated with a luxurious stay.\n\n4. **Tropical Tranquility Experience** - This name emphasizes the serene environment of the resort, inviting guests to immerse themselves in a calm and luxurious atmosphere.\n\n5. **Family Oasis Retreat** - This name highlights the family-friendly aspect of the resort while suggesting a luxurious and comfortable environment for all ages.","sources":""}

Notice the difference? This updated response helps you understand why the agent proposed these packages. With chain-of-thought prompting, you give the AI agent instructions to explain why it generated each package name. In this example, you brainstormed different ideas for package names in partnership with an agent. During the process, the agent provided examples to you with relevant context. This enables you to see beyond the content it created to the reasoning behind it. Over time, that insight will help you to get more out of every prompt!

Now it’s time for you to work with Prompt Builder using the chain-of-thought prompt technique. Once you’ve completed the steps in the challenge, click Check Challenge to earn this badge.

Congratulations! You’re well on your way to using more advanced prompt techniques to get better results.

Resources

Share your Trailhead feedback over on Salesforce Help.

We'd love to hear about your experience with Trailhead - you can now access the new feedback form anytime from the Salesforce Help site.

Learn More Continue to Share Feedback