Sub topic 3
Template inputs: the record behind the prompt
This chapter assumes you know the Salesforce data model (objects, fields, relationships), can navigate Setup and permission sets, and know what an LLM prompt is. You do not need to build a Flow or write Apex yet.
What a template input is
A prompt template in Prompt Builder is reusable text. It has no data of its own. A template input is a declared slot that tells the template what kind of data it will receive when it runs. For the record-based template types, the input is a single record of one object, such as a Case or an Account.
That record is the anchor of the template. Every merge field, related-record lookup, Flow resource, and Apex resource in the template starts from it.
How the input gets its value
You choose the input object when you create the template. At run time, the caller supplies a specific record, for example the Case a user has open. Prompt Builder then resolves every reference against that record and sends the finished text to the model.
Referencing the input
Inside the template you reach the input with the $Input prefix, followed by the object and field:
Case subject: {!$Input:Case.Subject}
Status: {!$Input:Case.Status}The part after $Input: is the input's object name. If the template is built on Case, you write Case.Subject. If you later change the input object, references to the old object no longer resolve, so choose the object deliberately at the start.
What the input is passed to
The same record is the starting point for the other resource types. This is why the input matters beyond merge fields.
- Flow resources receive the input record as a flow input variable. The flow can then query other objects based on it.
- Apex resources receive it through an invocable variable. In the Apex example in this tutorial, the request class has a field named
RelatedEntityof typeCase. - Relationship fields are followed from the input record, as in
{!$Input:Case.Account.Name}.
Because everything flows from one record, a template can only ground itself in data that is reachable from that record. If the data is not on the record, not on a related record, and not something a Flow or Apex method can look up from it, the template cannot use it.
Choosing the right input object
Pick the object that the user is working on when they invoke the prompt.
| Situation | Good input object | Why |
|---|---|---|
| Summarize a support case | Case | The case fields are direct merge fields. Account and Contact are one hop away. |
| Draft an email about an opportunity | Opportunity | Amount, stage, and close date are on the record. |
| Describe an account's health | Account | Account fields are direct. Orders and cases need a Flow or Apex. |
A common mistake is to anchor on a parent object because it holds more data. Starting from Account to summarize a single case means the template cannot tell which case you mean. Anchor on the narrowest record that identifies the task, then reach upward through relationships.
Common errors
- Blank values in the output. The field is empty on the record, or the running user cannot see it. The template still resolves, but with nothing in that spot. Tell the model what to do with missing values, as the sample template does: "If a value above is empty, say it is not provided. Do not guess."
- Wrong object name in a reference.
{!$Input:Account.Name}in a Case template fails because the input is a Case. Use{!$Input:Case.Account.Name}. - Expecting data the input does not carry. A merge field gives you what is stored on the record at the time the template runs. It does not run queries.
Checking your understanding
Exercise
A template is built with Case as its input object. You want to insert the name of the account that owns the case. What merge field do you write, and why can't you write {!$Input:Account.Name}?
Show answer
Write {!$Input:Case.Account.Name}. References start from the input object, which is Case, and then follow the Account relationship field to the parent record. Account is not the input object, so {!$Input:Account.Name} does not resolve.
Exercise
A teammate wants to summarize one support case but sets the template input to Account so more data is available. What problem does this create, and what is the better design?
Show answer
The template receives an Account record and cannot identify which of the account's cases to summarize. The better design is to use Case as the input and reach the account's data through relationship fields such as Case.Account.Name.