Sub topic 4
Inputs, resources and merge fields
This chapter assumes you know the Salesforce data model (objects, fields, records) and have opened Prompt Builder. You should also know that a prompt template is saved prompt text that an agent action can call.
Inputs: what the caller hands to the template
An input is a value that the template receives when it runs. In a Flex template, you declare inputs when you create the template. Two kinds are common:
- A record input has an object type, such as Case. The caller passes a record ID, and the template can read that record's fields.
- A free text input holds a string, such as a tone or a question.
The input's name matters. Merge fields and callers both refer to it by name, so a mismatch breaks the template.
Resources: where the template gets its data
A resource is any source of data you can insert into the prompt text. The main ones are:
| Resource | What it supplies | Typical use |
|---|---|---|
| Record field | A field on an input record | Case subject, status |
| Related list | Child records of the input record | Recent case comments |
| Flow | The output of an autolaunched flow | Data that needs logic or a query |
| Apex | The output of an invocable Apex method | Calculated or external data |
| Another prompt template | The generated text of a different template | Reusing a standard summary |
The next chapter covers related lists, Flow and Apex in detail. Here, focus on record fields.
Merge fields: placing the data in the text
A merge field is a placeholder in curly braces. When the template runs, Salesforce replaces it with the real value before the text goes to the model. The pattern for a record input is {!$Input:ObjectName.FieldApiName}.
You are a service assistant. Write a short, factual summary of the case below for a customer call hand-off.
Case number: {!$Input:Case.CaseNumber}
Subject: {!$Input:Case.Subject}
Status: {!$Input:Case.Status}
Description: {!$Input:Case.Description}
Rules:
- Use at most five sentences.
- Use only the information above. If something is missing, say it is unknown.
- Do not promise refunds or dates.In practice, you insert merge fields with the resource picker in Prompt Builder rather than typing them. The picker uses correct API names and shows which fields exist.
How the pieces connect at run time
The model never sees the placeholders. It sees only the resolved text, so a field that resolves to nothing leaves a gap in the prompt.
Grounding
Grounding means giving the model the facts it needs inside the prompt, so it does not guess. Merge fields do this. The rules at the end of the sample template also help:
- "Use only the information above" restricts the model to the grounded data.
- "If something is missing, say it is unknown" gives the model a safe response when a field is empty.
Common errors
- Wrong API name. A custom field needs its
__cname. Use the picker to avoid typos. - Empty fields. A blank Description resolves to blank text. Without a fallback rule, the model may invent content.
- Missing access. The template runs with the permissions of the running user. If that user cannot read a field, the value may not appear. Check field-level security when output looks incomplete.
- Input name mismatch. Callers refer to the input by name. In the Apex call, the key is
'Input:Case'. If you rename the input, update every caller. - Too much data. Inserting many long fields or large related lists wastes space and can bury the facts that matter. Include only what the task needs.
Why this matters for agents
When the template becomes an agent action, the agent supplies the input, usually a record ID taken from the conversation. The merge fields do the rest. A template with clear inputs and focused merge fields is easier for the agent to call correctly. Mapping those inputs is covered in a later chapter.
Exercise
A template summarizes a Case using {!$Input:Case.Description}. Some summaries mention details that are not in the case. The Description field is empty on those cases. What two changes reduce the problem?
Show answer
First, add a rule such as "Use only the information above. If something is missing, say it is unknown." Second, add more grounding, for example other fields or related comments, so the model has real facts. Previewing with an affected record confirms the Description resolves to blank.