Sub topic 7
Designing outputs the agent can explain
This chapter assumes you have read the earlier chapters on action metadata and input design. It also assumes you can read basic Apex or build Flow variables. You should know that an Agentforce agent uses a large language model (LLM) to decide what to say after an action runs.
What the agent does with an output
When an action finishes, the platform hands its output values to the agent. The agent reads them as text in its working context. It then writes a reply from that text and from the topic instructions.
The agent cannot see your code, your Flow canvas, or your database schema. It sees the output names, labels, descriptions, and values. Your output design therefore decides three things:
- Whether the agent can tell what each value means.
- Whether it has enough information to answer the customer's question.
- Whether it will repeat something it should not, such as an internal ID or a long block of raw data.
Weak outputs make the agent guess. A guess is the most common source of a wrong or invented answer after an action succeeds.
Return the answer, not the record
A common mistake is to return everything the action can reach. Suppose the customer asks, "Where is my order?" An Apex action could return the whole Order record with 40 fields. The agent must then decide which fields matter. It may mention a field the customer did not ask about, or misread a field with a cryptic API name.
Design from the question backward:
- Write down the question the customer is asking.
- List the smallest set of facts needed to answer it.
- Return those facts as separate, named outputs.
For an order status action, that set is usually the status, an expected delivery date if one exists, and a message. It does not include the record ID, the owner, or the audit fields.
The table below shows the same action with a poor and a better output design.
| Aspect | Poor design | Better design |
|---|---|---|
| Number of outputs | One `Result` string holding a JSON dump | Three outputs: status, delivery date, message |
| Names | `f1`, `val`, `out` | `Order Status`, `Expected Delivery Date`, `Result Message` |
| Descriptions | "Output of the action" | "Current status of the order, such as Draft or Activated. Empty if no order was found." |
| Identifiers | Returns 18-character record IDs | Returns the order number the customer knows |
| Volume | All related line items | Item count plus the first few item names |
Write output descriptions for the reader
An output description tells the agent what the value is, what values to expect, and what an empty value means. The three parts do different jobs.
- What it is. "Current status of the order."
- What values to expect. "Such as Draft or Activated." Examples help the agent phrase the reply and spot an unexpected value.
- What empty means. "Empty if no order was found." Without this, the agent may treat a blank as "not yet known" and say the order is pending.
Compare these two descriptions for the same output:
Weak: Label: Result
Description: Output of the action
Stronger: Label: Order Status
Description: Current status of the order, such as Draft or Activated. Empty if no order was found.The weak version forces the agent to infer the meaning from the value alone. If the value is A, the agent cannot know it stands for Activated.
Prefer readable values over codes
The agent reads values as language. Values already in the customer's vocabulary come through most reliably.
- Return picklist labels, not internal API values, when the two differ.
- Return dates in a form you have tested. A
Dateoutput is formatted by the platform. AStringsuch as2026-12-05is passed as written. - Return amounts with their currency in the description or in the message. A bare
149.5could be dollars, euros, or points. - Replace boolean flags with a clear label and description.
Is Refundablewith a description of "True if the order can still be refunded" works. A flag calledflag2does not.
Do not make the agent translate codes. If an integration returns ST_07, map it to "Awaiting payment" inside the action. The mapping lives in code you can test. A mapping left to the agent depends on model behavior and can change between runs.
Add a result message
A short plain-language message is often the most useful output you can return. It states the outcome in the words you want the agent to use. It is also the best place to describe the unusual cases, such as no match or partial results.
Keep the message factual and short. One or two sentences is enough. State what happened, not what the agent should do next. Instructions for what to do next belong in topic instructions, covered in a later chapter.
Return the message alongside the structured values, not instead of them. The structured values let the agent answer follow-up questions. The message gives it safe wording for the main answer.
Worked example: summarizing open cases
This Apex action answers "What cases do I have open?" It returns a count, a short list of recent subjects, and a message. It caps the list at three subjects so the output stays small however many cases exist.
public with sharing class GetOpenCaseSummary {
private static final Integer MAX_SUBJECTS = 3;
public class Request {
@InvocableVariable(
label='Account Id'
description='The Salesforce Id of the customer account, taken from the conversation context. Do not ask the customer for it.'
required=true
)
public Id accountId;
}
public class Response {
@InvocableVariable(
label='Open Case Count'
description='Number of open cases for the account. Zero if there are none.'
)
public Integer openCount;
@InvocableVariable(
label='Recent Case Subjects'
description='Subjects of up to three of the newest open cases, separated by semicolons. Empty if there are no open cases.'
)
public String recentSubjects;
@InvocableVariable(
label='Result Message'
description='A short plain-language message describing the outcome, including when the account has no open cases.'
)
public String message;
}
@InvocableMethod(
label='Get Open Case Summary'
description='Counts the open support cases for one account and lists the newest subjects. Use when the customer asks what cases they have open.'
)
public static List<Response> getSummary(List<Request> requests) {
Set<Id> accountIds = new Set<Id>();
for (Request r : requests) {
accountIds.add(r.accountId);
}
Map<Id, List<String>> subjectsByAccount = new Map<Id, List<String>>();
Map<Id, Integer> countByAccount = new Map<Id, Integer>();
for (Case c : [
SELECT AccountId, Subject
FROM Case
WHERE AccountId IN :accountIds AND IsClosed = false
WITH USER_MODE
ORDER BY CreatedDate DESC
]) {
Integer count = countByAccount.containsKey(c.AccountId) ? countByAccount.get(c.AccountId) : 0;
countByAccount.put(c.AccountId, count + 1);
if (!subjectsByAccount.containsKey(c.AccountId)) {
subjectsByAccount.put(c.AccountId, new List<String>());
}
List<String> subjects = subjectsByAccount.get(c.AccountId);
if (subjects.size() < MAX_SUBJECTS) {
subjects.add(c.Subject);
}
}
List<Response> results = new List<Response>();
for (Request r : requests) {
Response res = new Response();
res.openCount = countByAccount.containsKey(r.accountId) ? countByAccount.get(r.accountId) : 0;
if (res.openCount == 0) {
res.message = 'This account has no open cases.';
} else {
res.recentSubjects = String.join(subjectsByAccount.get(r.accountId), '; ');
res.message = 'This account has ' + res.openCount + ' open case(s).';
}
results.add(res);
}
return results;
}
}Several design choices here are worth copying:
- Bounded output. The subject list is capped at three, so a large account does not flood the agent's context.
- Explicit zero.
openCountis0, not null, when nothing matches. A null count is ambiguous. - A message for the empty case. The agent has exact wording for "no open cases" and does not need to infer it.
- One response per request. The method returns a response for every request, in order, which keeps bulk calls correct.
Control size and structure
The agent works inside a limited context. Large outputs cost space and raise the chance of error.
- Cap lists. Return the top few items and a total count. Say in the description that the list is partial.
- Flatten when you can. Several simple outputs are easier for the agent than one nested structure. Use a list of records only when the agent must compare items.
- Sort before returning. If order matters, sort in the action and say so in the description, such as "newest first."
- Do not paste raw payloads. A raw API response or long HTML body makes the agent read through noise. Extract the fields you need.
When a result is naturally a list, a single formatted text output is sometimes more reliable than a list of objects. The agent can quote it directly. Use that approach only when the agent does not need to filter or sort the items.
Which outputs the agent and customer see
Some outputs help the agent reason but should not appear in the conversation. Others are meant to be shown. Agentforce Builder has output settings that control this, and the next chapter covers them in detail. For now, apply one rule to your design: each output should have a clear purpose, either "the agent needs this to answer" or "the customer should see this." An output with neither purpose should be removed.
Common output mistakes
- Empty strings that mean different things. A blank can mean "not found," "not applicable," or "an error occurred." Use the message output to tell them apart.
- Duplicate meaning. Two outputs called
StatusandOrder Statusinvite the agent to pick one at random. Give each a distinct name and description. - Descriptions copied from the field help text. Field help is written for admins. Write for a reader who knows nothing about your data model.
- Hidden units and formats. State units, currency, and time zone where they matter.
- Output that restates the input. Echoing the order number is useful in a message. Returning it as a separate output adds noise.
Check your design
Before you move on, review each output against these questions:
- Does the label say what the value is, in the customer's words?
- Does the description give example values and say what empty means?
- Is the value small, readable, and free of internal codes?
- Does a message cover the no-result case?
- Would you be comfortable if the agent repeated this value to the customer?
Exercise
An action named Check Warranty returns one output called Result, with the description "Warranty data". The value is a JSON string of 30 fields. The agent sometimes reports the wrong expiry date. Describe how you would redesign the outputs.
Show answer
Return only what the customer's question needs as separate outputs: Warranty Status (for example Active or Expired), Warranty Expiry Date (a Date), and Result Message. Give each a specific label and a description that includes example values and says what an empty value means, such as "Empty if no warranty is registered for this product." Move any code mapping, such as turning coverage codes into plain labels, into the action. Drop the other 27 fields. The agent then reads one value for the expiry date instead of searching a JSON string, so it has less room to pick the wrong field.
Exercise
Why does the Open Case Summary example return an openCount of 0 and a message when no cases match, rather than returning a null count with no message?
Show answer
A null count is ambiguous. The agent could read it as "unknown," "not loaded," or "an error." An explicit 0 states the fact, and the message gives the exact wording to use. Together they let the agent say plainly that the account has no open cases, without guessing.