Prompt Builder from Salesforce is a powerful tool that enables organizations to add generative AI capabilities to their business application. It allows organizations to create and manage prompt templates.
Sets of questions or instructions provided to a large language model to generate relevant content. To learn more complete the trailhead module below
- Zero Shot
- Few-Shot
- Chain of Thought (COT)
- Tree of Thoughts (TOT)
- Graph Prompting
A useful resource to learn about all of the above and much more is below
- Solve for Halucinations
- Provide more context as a part of Prompt.
- Ground prompts with current and latest information
- Prevent information from leaking to LLM
Click on the below trailhead module to learn more about the licenses needed for enabling Prompt Builder for your Salesforce org.
Einstein Pricing: Quick Look Trailhead
Below is link to get a free trial org with Prompt Builder access. Trial org expires in 5 days.
Prompt Builder offers a range of customizable templates, including:
- Sales Email prompt templates
- Field Generation prompt templates
- Record Summary prompt templates
- Flex prompt templates
These templates can be used across different AI tools in Salesforce.
- App Builder for Lightning Pages
- Salesforce Flows (Including Screen Flows)
- Apex
- Einstein Copilot
Below is an example code that shows how to ground prompt templates with Apex
public with sharing class ExamplePromptTemplateResolver {
@InvocableMethod(
capabilityType='<this depends on the prompt template type>'
)
public static List<Response> getContactsPropertyInterest(List<Request> requests) {
// Retrieve inputs
Request input = requests[0];
Object1__c input1 = input.input1;
Object2__c input2 = input.input2;
// Create expected response
List<Response> responses = new List<Response>();
Response output = new Response();
// Example Business logic to add to the prompt
output.Prompt = 'Recommended Products:';
for(Product__c prd : ProductController.getSimilarProducts(input1.Id, input1.Product_Family__c)) {
output.Prompt += '\n' + 'product name:' + prd.Name + ', Picture URL:' + prd.Picture_URL__c + ', MSRP:' + prd.MSRP__c;
}
output.Prompt += '\n';
responses.add(output);
return responses;
}
// Class that represents the template inputs that are passed to the class
public class Request {
@InvocableVariable
// Ensure that the input1 variable is same name with proper case as you configured in the Prompt Builder
public Object1__c input1;
@InvocableVariable
public Object2__c input2;
}
// Class that represents the data that will be added to the template
// when it's resolved
public class Response {
@InvocableVariable
public String Prompt;
}
}
Capability Type | Value |
---|---|
Sales Email | PromptTemplateType://einstein_gpt__salesEmail |
Field Completion | PromptTemplateType://einstein_gpt__fieldCompletion |
Flex Templates | FlexTemplate://template_API_Name |
Record Summary | PromptTemplateType://einstein_gpt__recordSummary |
For Flex template type make sure template_API_Name matches the prompt template API Name field defined in Prompt Builder
For more examples refer to the resources below
Apex Developer Guide Examples for Resolving Prompt Templates via Apex
Use Connect in Apex to call a prompt template from Apex code.
String promptTemplateDeveloperName = '';
// Prepare input for generating prompt template
ConnectApi.EinsteinPromptTemplateGenerationsInput promptGenerationsInput = new ConnectApi.EinsteinPromptTemplateGenerationsInput();
// Map for holding input parameters
Map<String, ConnectApi.WrappedValue> inputParams = new Map<String, ConnectApi.WrappedValue>();
Map<String, String> input = new Map<String, String>();
// Set input parameters. Usually set the record Id for resolving the template
input.put('id', inputId);
// Add wrapped values
ConnectApi.WrappedValue inputValueMap = new ConnectApi.WrappedValue();
inputValueMap.value = input;
inputParams.put('Input:<input_variable_from_prompt_builder>', inputValueMap);
// Set hyper parameters
promptGenerationsInput.inputParams = inputParams;
promptGenerationsInput.additionalConfig = new ConnectApi.EinsteinLlmAdditionalConfigInput();
promptGenerationsInput.additionalConfig.numGenerations = 1;
promptGenerationsInput.additionalConfig.enablePiiMasking = false;
promptGenerationsInput.additionalConfig.applicationName = ApplicationConstant.APP_NAME;
// Set if it's a preview or not
promptGenerationsInput.isPreview = false;
// Call the service to generate messages for the prompt template
ConnectApi.EinsteinPromptTemplateGenerationsRepresentation generationsOutput = ConnectApi.EinsteinLLM.generateMessagesForPromptTemplate(promptTemplateDeveloperName, promptGenerationsInput);
// Consume response
ConnectApi.EinsteinLLMGenerationItemOutput response = generationsOutput.generations[0];
System.debug('Response: ' + response.text);
For more examples refer to the resources below
@patmcclellan Yes I recommend using a stub provider and mocking the responses for Unit testing