Sub topic 4
Inserting record fields with merge fields
This chapter assumes you know the Salesforce data model (objects, fields, relationships), can find Prompt Builder in Setup, and understand what a prompt to a large language model is. Flow and Apex come in later chapters.
What a merge field does
A merge field is a placeholder in a prompt template. When the template runs, Salesforce replaces the placeholder with the value from the record the template is anchored to. The model never sees the placeholder. It sees the resolved text.
The syntax for a field on the input record is:
{!$Input:ObjectApiName.FieldApiName}$Input refers to the template input you defined, Case in this chapter's example. The part after the dot is the API name of the field. For custom fields, use the API name with the __c suffix, such as Case.Escalation_Reason__c.
You can type merge fields by hand, or insert them from the resource picker in the template editor. The picker lists the fields you can reach from the input record, which helps you avoid typos in API names.
A first grounded template
The template below grounds the model in four fields of a Case record. It also tells the model what to do when a value is empty.
You are a support assistant. Summarize the case below in two sentences for an agent taking over.
Case subject: {!$Input:Case.Subject}
Status: {!$Input:Case.Status}
Priority: {!$Input:Case.Priority}
Description: {!$Input:Case.Description}
If a value above is empty, say it is not provided. Do not guess.Suppose the input Case has these values:
| Field | Value |
|---|---|
| Subject | Printer offline after update |
| Status | Escalated |
| Priority | High |
| Description | (empty) |
The model receives this resolved prompt:
You are a support assistant. Summarize the case below in two sentences for an agent taking over.
Case subject: Printer offline after update
Status: Escalated
Priority: High
Description:
If a value above is empty, say it is not provided. Do not guess.An empty field resolves to an empty string. The closing instruction then gives the model a rule for that case, so it can say the description is not provided instead of inventing one.
How resolution works
Resolution happens each time the template runs, so the model always sees current data. Resolution runs as the user who triggers the template. If that user cannot read a field, the field does not resolve to its value. Chapter 11 covers permissions in detail. For now, remember that a template can work for you and return thin output for a colleague with narrower field access.
Formatting of resolved values
Merge fields insert text. Several field types need attention:
- Picklists resolve to the label or value stored on the record, not to any explanation of what the value means. If "P1" matters, say so in the instructions.
- Dates and numbers resolve as formatted text. State the expected meaning in the prompt, for example "Close date (the date the deal is expected to close)".
- Long text fields can be large. A long Description or email thread adds a lot of text to the prompt, which affects size limits.
- Empty values resolve to nothing, as shown above.
Common errors
- Wrong API name.
{!$Input:Case.Subjct}fails to resolve. Use the picker, or copy the name from Object Manager. - Wrong object in the placeholder. The object name must match the template's input object. A Case template cannot use
{!$Input:Opportunity.Name}. - Fields the user cannot see. The preview looks fine for an admin but the output is poor for a user with limited access.
- No rule for empty values. Without one, the model may fill gaps with plausible but made-up text.
- Dumping every field. More fields do not mean better grounding. Extra values dilute the signal and use space. Include only what the task needs.
Checking your work
Before you use a template anywhere, open the template's preview, pick a real record, and read the resolved prompt. Look for unresolved placeholders, blank lines where you expected data, and values that look wrong. Chapter 10 covers preview and testing in full.
Exercise
A Case template contains {!$Input:Case.Description}. A support agent reports that summaries say "the description is not provided" for cases that clearly have descriptions when viewed by the admin. Name two likely causes and how you would check each.
Show answer
First, the agent may lack field-level security access to Description, so it resolves empty for them. Check the agent's profile and permission sets, and preview the template as that user or compare their field access to the admin's. Second, the template may be anchored to a different record than the agent expects, or the field may be empty on the specific record. Open the preview with that exact record and read the resolved prompt.
Exercise
Write the merge field line that inserts the Priority of a Case input record, and add one instruction that tells the model what to do if Priority is empty.
Show answer
Line: Priority: {!$Input:Case.Priority}. Instruction: "If Priority is empty, say it is not provided. Do not guess."