Sub topic 4
Grounding prompts with merge fields and resources
This chapter assumes you know Salesforce objects, records, fields and relationships. It also assumes you can open Prompt Builder in Setup with Einstein generative AI enabled.
What grounding means
A language model knows nothing about your customers. Grounding means putting real data from your org into the prompt before it reaches the model. Without it, the model invents plausible details. With it, the model writes from the facts you supplied.
In Prompt Builder you ground a prompt with merge fields and resources. You write them inside the template text, and Salesforce replaces them with real values when the prompt runs.
Merge fields
A merge field is a placeholder for a field value. Its syntax is {!$Input:Object.Field}. The part after $Input: is the input name, which comes from the record the template is based on. You can follow relationships, so {!$Input:Contact.Account.Name} reads the name of the contact's account.
This Sales Email style prompt uses merge fields from a Contact:
Write a short, friendly follow-up email to {!$Input:Contact.FirstName} {!$Input:Contact.LastName}, who works at {!$Input:Contact.Account.Name}.
Mention that we met recently and offer to schedule a call.
Keep it under 120 words and do not invent product details.In the editor you can type {! to pick fields from a list, which avoids typos. A misspelled field name is a common error, and the placeholder will not resolve.
Handling missing data
Merge fields resolve to whatever is stored. If a field is empty, the model gets a blank. Tell it what to do in that case:
Using the information below, write a one-sentence description of this account for a sales rep.
Account name: {!$Input:Account.Name}
Industry: {!$Input:Account.Industry}
Annual revenue: {!$Input:Account.AnnualRevenue}
If a value is empty, leave it out instead of guessing.The last line matters. It stops the model from filling gaps with made-up values.
Resources beyond single fields
Merge fields cover the base record and its parents. Larger tasks need more context, and Prompt Builder offers other resources for this:
| Resource | What it supplies | Typical use |
|---|---|---|
| Record fields | Values from the input record and related parent records | Names, industry, status |
| Related lists | Child records, such as contacts or cases on an account | Summaries of activity |
| Flow | Data or text returned by a Flow you build | Logic that needs queries or conditions |
| Apex | Data returned by an Apex class | Calculations or external lookups |
| Data Cloud | Unified data from Data Cloud | Cross-system customer data |
Availability depends on your edition and on the template type. Check the resource list in the template editor, because it shows only what that template can use.
The input name sets the syntax
The word after $Input: depends on the template type. Object-bound types such as Sales Email and Field Generation use the object name, like Contact or Account. A Flex template lets you define its inputs. The name you give an input becomes part of the merge field syntax. This Case summary prompt works for a Record Summary template, or for a Flex template whose input is named Case:
Summarize this case for a support manager in three bullet points: the problem, what has been tried, and the next step.
Subject: {!$Input:Case.Subject}
Description: {!$Input:Case.Description}If you rename a Flex input, update every merge field that uses it.
Common errors
- Referencing a field that is not on the template's object. The editor flags it, or the value stays blank.
- Dumping every field into the prompt. Extra data adds noise and uses up the prompt size limit. Include only what the task needs.
- Skipping an instruction for empty values.
- Asking the model for facts that no merge field supplies. It will guess.
Exercise
A Field Generation template writes a short account description. Preview shows "Annual revenue: " followed by nothing for one account, and the model writes "a company with about $50 million in revenue". What two changes fix this?
Show answer
First, add an instruction such as "If a value is empty, leave it out instead of guessing." Second, check that the AnnualRevenue merge field is spelled correctly and that the running user can see the field. With the instruction in place and a correct field reference, the model omits the missing value instead of inventing one.