Sub topic 2
Grounding Prompt Templates with Related Data and Agent Actions
Assume you know Salesforce objects, fields, records, permissions, Agentforce topics, and basic prompting. Grounding means giving a model trusted data to use instead of asking it to rely only on general training.
Grounding with related lists, Flow, and Apex
A prompt template can use an input record and merge fields such as a Case subject or status. Related lists need more care. Instead of assuming that the model can discover child records, provide the related data through a supported resource:
- Use a related-list resource when the template needs records such as Case Comments or Contact Cases.
- Use Flow when you need filtering, sorting, formatting, or data from several objects.
- Use Apex when the preparation requires custom queries or business logic that Flow cannot express easily.
The resource should return only the fields and records the template needs. Add clear instructions for empty results and conflicting values.
Trust Layer and model selection
The Einstein Trust Layer applies Salesforce security and privacy controls around supported generative AI requests. Configure access carefully, and do not expose fields that the user is not authorized to see. Select a model based on the task:
- A fast, smaller model may fit short classification or summarization.
- A stronger model may fit complex instructions or several grounded sources.
- Test factual accuracy, latency, cost, and output length before choosing.
The Trust Layer does not make an unclear prompt correct. Ground the prompt, define boundaries, and require the model to identify missing information.
> Callout note > Grounding supplies evidence. It does not automatically enforce business rules. Keep authorization, validation, and record updates in Salesforce automation or code.
Adding the template to an agent as an action
Create or select the prompt template, activate a tested version, and add it as an action in Agent Builder. Map the action input to the record or value the template expects. Map the generated text output to the agent's response.
For example, a Case Summary action can accept a Case record, invoke the template, and return its text without changing the Case.
Writing topic instructions that call the action
Topic instructions determine when the agent uses the action. State the trigger, required input, and output behavior:
- When the user requests a Case summary, identify the Case.
- Ask for the Case number if it is missing.
- Invoke the Case Summary action after identifying the Case.
- Return the action output without adding unsupported facts.
- Do not update the Case or promise dates or refunds.
Exercise
A template needs the five most recent Case Comments, filtered to public comments. Which resource is usually the best fit?
Show answer
Use Flow for straightforward filtering and sorting. Use Apex if the selection requires custom logic or data access that Flow cannot provide.