Sub topic 3
Template inputs: the record behind the prompt
What this chapter covers and what you need first
This chapter explains template inputs. An input is the value a prompt template receives when it runs. In most Prompt Builder templates, the input is a single record, such as one Case. Every merge field in the template reads from that record.
I assume you already know these things:
- The Salesforce data model: objects, fields, and lookup and master-detail relationships.
- Where to find Setup and how permission sets grant access.
- What a prompt for a large language model is.
- The basics of Flow Builder and the shape of an Apex class.
The previous chapter introduced prompt templates and template types. Here you will learn how a template gets its data. The next chapter covers merge fields in detail.
A template is a function, and inputs are its arguments
A prompt template is text with placeholders. Placeholders cannot be filled until the template knows which record it is working on. The template therefore behaves like a function. You define it once, and each call passes in different arguments.
For example, a template that summarizes a Case needs to know which Case. If an agent opens Case 00001026, the platform passes that record in. If another agent opens Case 00001027, the same template runs with a different record. The template text does not change. Only the input changes.
This design has three consequences:
- One template serves every record of the object. You do not write a template per case.
- Every value in the final prompt traces back to the input record or to a resource attached to the template. Nothing is guessed.
- The input record decides which data the template can reach. Its fields are available directly. Its related records are available through relationships. A Flow or Apex resource can reach anything else, but it needs the input record to know where to start.
Where the input record comes from
The platform resolves the input at run time. The caller depends on where the template is used. Typical callers are:
- A Lightning record page, where a component or action runs the template for the record on screen.
- A field generation setup, where a text field on the record is populated by the template.
- A Flow, Apex code, or an agent action that invokes the template and passes a record.
- The Prompt Builder preview, where you pick a sample record by hand.
In each case a record ID identifies the record. The platform loads the record, applies the running user's access rules, and then substitutes values into the template. If the caller cannot supply a record of the right object, the template cannot run.
Input types depend on the template type
The template type decides what inputs you can define.
| Template type | Typical input | Who defines the input |
|---|---|---|
| Field Generation | One record of a chosen object | The type fixes the shape. You choose the object. |
| Record Summary | One record of a chosen object | The type fixes the shape. You choose the object. |
| Sales Email | A recipient and a related record | The type fixes the shape. |
| Flex | Zero or more inputs of types you choose | You define each input. |
Check the exact input options in your org's release, because Salesforce adds and renames options between releases. The pattern stays the same. Fixed-shape types give you one anchor record. The Flex type lets you declare your own inputs, which can be records or plain text.
Flex inputs
A Flex template starts with no assumptions. You add each input yourself and give it a name and a type. A record input asks for an object, for example Case. A text input accepts a string. Because you name the input, the name appears in every merge field that reads from it.
A Flex template can take several inputs. A template that compares a Case with an Account can declare both as record inputs. This is more flexible than a fixed-shape type. It also means the caller must supply every input.
The syntax: `$Input`
Merge fields that read an input start with $Input, followed by a colon, the input name, and the field path.
{!$Input:Case.Subject}Read it from left to right:
$Inputsays the value comes from a template input.Caseis the name of the input. For a record input this is the object name.Subjectis a field on that record.
The same template from this tutorial's plan shows several fields from one input:
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.All four merge fields point at the same record. Whichever Case the caller passes in, Subject, Status, Priority, and Description come from that Case.
In the Prompt Builder editor you do not have to type the syntax. Typing {! opens a picker that lists the inputs, resources, and fields you can insert. Using the picker avoids spelling errors in field names.
Where resources fit in
Resources are the other place a template gets data. A resource is a Flow or Apex action attached to the template, or a related-record path. Resources need the input record. A Flow resource, for instance, receives the input record as its starting point, then queries more data and returns text.
This diagram shows why the input record is the anchor. Remove it and none of the three data paths has a starting point.
Walking through a run
Follow one run of the Case summary template to see how the input shapes the result.
- An agent opens a Case page and clicks an action that runs the template.
- The platform takes the Case ID from the page and passes it as the
Caseinput. - It loads the Case, respecting the agent's field-level security.
- It replaces each
{!$Input:Case.…}placeholder with the field value. A field the agent cannot read resolves to nothing. An empty field resolves to nothing too. - It sends the finished text to the model and returns the response.
Step 4 explains why the closing instruction in the template matters. "If a value above is empty, say it is not provided" gives the model a rule for blank values. Without that rule, the model may invent a plausible value for the gap. The prompt-design chapter returns to this.
The anchor record and object choice
When you create a Field Generation or Record Summary template you choose an object. This choice is not cosmetic. It controls three things:
- Which fields appear in the merge field picker.
- Which relationships you can follow to related records.
- Where the template can be used. A Case template can only run for Case records.
Pick the object that holds the most of the data your prompt needs. If the prompt is about an Account but the data you need lives mostly on Cases, you have two options. You can anchor on Account and fetch Cases with a Flow. Or you can anchor on Case and read Account fields through the Case's relationship. The right answer depends on where the template will run. A template for a Case page should anchor on Case.
You cannot change the object of a template casually after you have written merge fields. Fields that do not exist on the new object stop resolving. If you pick the wrong object, build a new template or new version and move the text across.
Edge cases and common errors
Empty values
An empty field produces an empty string, not an error. The model then sees a label with nothing after it:
Priority:A model may read this as missing, or may fill it in. Instruct it explicitly, as the example template does.
Fields the user cannot see
The template runs with the permissions of the running user. If field-level security hides Description from that user, the merge field resolves to blank for them. Two agents can therefore get different prompts from the same record. This is correct behavior, but it surprises people when they compare outputs. The last chapter covers permissions in full.
Long text and rich text
A long text area can be large. Merge fields insert the whole value, which can use up a lot of the prompt's size budget. Rich text fields may carry markup. Consider whether the model needs the full field or whether a Flow should trim it.
Wrong or missing input at the call site
A caller that passes no record, or a record of the wrong object, cannot resolve the template. When you call a template from Flow or Apex, make sure the record you pass matches the object the template expects. In the preview, an empty record picker is the equivalent mistake.
Hard-coded values
Do not type a record's value into the template when an input would supply it. A typed-in customer name works for one test and gives wrong output for every other record. Always use a merge field for values that vary.
Checking your understanding of the input
When you debug a template that gives odd output, work through this order:
- Confirm the template's object or input type matches the records the caller passes.
- Confirm each merge field names the right input and a field that exists.
- Open the preview with a record you know well and read the resolved prompt, not the model's answer.
- Check whether the running user can read each field.
- Look for fields that are empty on that record.
Most grounding problems end at step 3. The resolved prompt shows exactly what the model saw. If a value is wrong or missing there, the cause lies in the input or the fields, not in the model.
Summary of the model
A template is reusable text. An input is the record, or other value, that a caller supplies each time it runs. Merge fields with the $Input prefix read from that input. Flow and Apex resources start from the same input and return more data. The object you choose for the input fixes which fields and relationships you can use, so choose it deliberately.
Exercise
A Flex prompt template has a record input named Case. A teammate writes {!$Input:Account.Name} in the template and the preview shows an empty value. What is the most likely cause, and how would you fix it?
Show answer
The merge field refers to an input named Account, but the template only defines an input named Case. Either the input name is wrong or the intended data lives on the Case's parent. Fix it by following the relationship from the existing input, as in {!$Input:Case.Account.Name}. Or, if you really need an Account as a separate input, add an Account record input to the Flex template and make sure every caller supplies it.
Exercise
Two support agents run the same Case summary template on the same Case. One summary mentions the case description and the other does not. The template and the record are identical. Name two likely causes and say how you would confirm each.
Show answer
First, field-level security may hide the Description field from the second agent, so the merge field resolves to blank for that user. Confirm by checking the second agent's permission sets and profile for read access to Case.Description. Second, the two agents may be running different versions of the template, or the second may have a template that does not include the Description merge field. Confirm by comparing the template version and by previewing as each user or checking the resolved prompt. In both cases, read the resolved prompt in the preview, because it shows what the model actually received.