A prompt template is a pre-designed structure in Salesforce, specially designed to create personalized prompts by filling the substitute with particular details of customers, products, and more. This approach strengthens the creation of prompts and lets teams generate data-driven content.
Every time a prompt template is used, it automatically merges the data to create a unique & personalized prompt.
With the help of Salesforce CRM data through merge fields and Flow Builder, these templates dynamically integrate complex logic and decision trees, enhancing personalization. The main agenda of this approach is to streamline B2C communications, delivering a unified voice while saving time & effort.
The skill of creating precise prompts to generate accurate and useful responses is called prompt engineering. However, prompt engineering comes with some challenges.
Let’s have a look at them:
Top 5 Prompt Engineering Challenges
Complexity of Adding Business Context
Integrating specific business context into prompts is challenging without manually inputting extensive data, making the process cumbersome and error-prone.
Data Security Concerns
Ensuring a secure method to share sensitive data with the LLM is crucial, as businesses must protect customer information and internal intellectual property.
Seamless Integration Needs
AI-powered tools are most effective when fully integrated into your workflow, eliminating the need to switch back and forth between the AI output and your work tasks.
Manual Data Entry
The lack of an easy way to incorporate business-specific details into prompts necessitates tedious and time-consuming manual data entry.
Obligation to Protect Data
Businesses face the dual challenge of leveraging AI while adhering to strict data protection obligations for customer and internal data.
Source: https://youtu.be/UuPWXstNjgs
Source: https://youtu.be/UuPWXstNjgs
Source: https://youtu.be/UuPWXstNjgs
Source: https://youtu.be/UuPWXstNjgs
Source: https://youtu.be/UuPWXstNjgs
Source: https://youtu.be/UuPWXstNjgs
Sign Up for a Trial Org with Einstein Generative AI
- To participate in the hands-on activities, we need to obtain a special trial organization that includes Einstein Generative AI and your sample data. This trial organization is available for a limited period of 5 days, so ensure you complete everything before it expires.
- Fill out the form. Enter an active email address where you can receive the email confirmation of the new account.
- After completing the form, click on ‘Sign Me Up.’ A confirmation message will appear on the screen.
- You will receive an email from support@salesforce.com with the subject “Finish resetting your Salesforce password” once your organization has been created (this may take a few minutes).
- Identify and save your username.
- Click the link to reset your password
- You are now logged in successfully to your special trial org.
- Connect Your Trial Org to Trailhead by going to the bottom of the challenge page and clicking on the ‘: ’ icon and then select ‘Connect Org’ and enter the credentials you received on your email.
- On the login screen, enter the username and password for the trial org you just set up. Note: If you receive an error message, refresh your browser.
- On the Allow Access screen, click Allow.
- On the “Want to connect this org for hands-on challenges?” screen, click Yes! Save it. You are redirected to the challenge page and ready to use your new trial org to earn this badge.
Create a Field Generation Prompt Template
In this demo, we want a case summary to appear in a text field on the record. To save a little time, Trailhead has already created a field named Quick Summary and placed it into the page layout.
At this point there’s nothing special about it, but let’s change that! You start by creating a prompt template.
- If you don’t already have your Einstein AI-enabled trial org open, scroll down to the Challenge section and click Launch to open it.
- Click on Setup and the setup page opens in a new tab.
- In the Quick Find box, enter Einstein Setup, then click Einstein Setup.
- Turn on Einstein by clicking the toggle. It may already be on if you’ve completed the Quick Start: Einstein Copilot project.
- Refresh your browser window. This reveals new admin settings now that Einstein is enabled.
- In the Quick Find box, click on Prompt Builder under Einstein Generative AI.
- Click New Prompt Template.
- New Prompt Template button – for this example, you use the Field Generation type of prompt template, so leave that as is.
- For Prompt Template Name, enter Summary in Glance.
- For API Name, enter Summary_in_Glance.
- For Template Description, enter Brief about case details.
- For Object, find and select Case.
- For Object Field, find and select Quick Summary.
- Click Next.
Great! Now, you’ve the beginning of a prompt template. To complete it, write clear instructions that explain what you want from the LLM.
As you learned in the Prompt Fundamentals badge, adding details like the overall goal, size limits, and some guidelines can improve results.
Creating a good prompt is a bit of an art, so for this project, we’ll provide you with a prompt that is proven to work well.
1. Paste the following text into the Prompt Template Workspace.
Provide a summary of the merged content from the comment bodies in COMMENTS, the text from SUBJECT, the priority level indicated by PRIORITY, and the type of case represented by TYPE.
Ensure the response is brief and contained within a single short paragraph.
2. For Models, choose OpenAI GPT 4
There are several models to choose from in your Einstein AI-enabled org, and OpenAI GPT 4 produces some great results.
3. Click in the Resource box to open the list of resources.
4. Click Case, then click Comments.
A merge field is inserted into text as blue text.
Repeat the same for all the rest 3 fields written in red letters (Subject, Priority, Type).
5. In the Related Record box, find and select case 00001024
6. Click Save & Preview & tthenActivate
Enable Dynamic Forms for Cases
- While still on the Prompt Builder page, verify that you’ve clicked Activate.
- In the App launcher, search Cases and select All Open Cases list view, and click on case number 0000102,4, and click the setup icon, and click Edit Page.
- Click the Setup icon and click Edit Page.
- Select the contents of the Details section, & With the Details section selected, click Upgrade Now in the Record Detail to upgrade to Dynamic Form and click Next.
- Select the Case Layout radio button & Click Finish.
- In the Details section, click the Quick Summary field. For Prompt Template, find and select Summary in Glance & you can refer to the below screenshot to cross-check the steps.
Let’s try it out!
- Click the Edit/Pencil icon on the Quick Summary field.
- Click on the right of the field. This automatically opens up the Einstein overlay, using your prompt template to start a new conversation. In a moment Einstein will suggest a case summary. Again, yours may appear a little different than ours.
- This allows your users to review the summary and even continue the conversation with Einstein to collaborate on a revised version. In this example, simply accept the first suggestion. There should be a ‘Use’ button in the Einstein overlay. If it’s not there, refresh the page and repeat steps 1 and 2
- Click Use.
- Click the X to close the Einstein overlay. Notice that the Quick Summary field is filled in.
- See the below screenshot for reference:
Source: https://d3nqfz2gm66yqg.cloudfront.net/images/20240202123914/Prompt-Template-Lifecycle-v2.png
Steps for Invoking Prompt Template From Flow
- Navigate to the setup page and in the quick find box search ‘Flow’ and click on the ‘Flow’ under the Process Automation section and click on ‘New Flow’ as shown below:
- Select ‘Screen Flow’ from the given type of flows & click on ‘Create’.
- Select the ‘Get Records’ element by clicking on the + icon and query the required cases. Here, I have queried the case on which page the user currently is as shown below:
Note: recordId (Case-sensitive) variable automatically pulls the id of the object from the URL on which the user is currently.
- In Flow Builder, add an Action element to your flow. In the New Action window, select the Prompt Template category, and then select the name of the prompt template to use.
The API name for each action is prefixed with generatePromptResponse.l
- I have added a screen at the end to show the output of the prompt.
- Now you can Save and Activate your flow.
- Now place this screen flow on the Detail page of the Case object and you will see the below response:
Invoking Prompt Template From Apex
- We are using the same prompt template with a minor change of one additional line in the end, and our prompt template will look like:
- We need to create an apex class in our org to invoke our prompt template as given below:
Apex Class Code (You can modify according to your business requirement)
Calling the method in Anonymous Window:
Result of Apex:
I am getting the result in the JSON format, so I have used ‘JSON Viewer’ website to see the JSON in readable format:
JSON Text:
Click on ‘Viewer’ button to see it in the readable format:
You can click on the ‘+’ icon to see the more granular details
Steps for Invoking Prompt Template From REST API
- Navigate to setup and search for ‘App Manager’ and click on ‘New Connected App’ as shown below:
Next, give the name to your app & the email & then select the following settings in “API (Enable OAuth Settings)” section as shown below to streamline the process & save the app
NOTE: I am using the same apex class as used in the above case.
- Once the connected app is created, you can access the ‘Client ID’ and ‘Client Secret’ that is required at the time of authorization in Postman. So, keep these 2 things safe in your notepad or some text editor.
- Next step is to log into the ‘Postman’ app either online or offline to test our API. Perform the necessary actions to authorize Postman.
- Now, replace the mentioned prompt template name & the base url with your actual prompt template name & base url respectively. See the below image for more clarity:
- Finally, select ‘POST’ method to generate response & in the body pass the required parameters like I did as shown below and after all of that hit the API by pressing the ‘Send’ button & see the response.
- Response I got –
For Reference, please go through the following links:
Prompt Template Generations Resource
Share This Blog
Table of contents
- Top 5 Prompt Engineering Challenges
- Complexity of Adding Business Context
- Data Security Concerns
- Seamless Integration Needs
- Manual Data Entry
- Obligation to Protect Data
- Sign Up for a Trial Org with Einstein Generative AI
- Create a Field Generation Prompt Template
- Enable Dynamic Forms for Cases
- Let’s try it out!
- Steps for Invoking Prompt Template From Flow
- Invoking Prompt Template From Apex
- Steps for Invoking Prompt Template From REST API