Sub topic 10
Describing action inputs and outputs
An action is only useful if the agent can fill in its inputs correctly and make sense of what comes back. The agent never sees your Flow or Apex code. It sees a name, a description, and a list of inputs and outputs. This chapter covers how to describe those so the agent uses them correctly.
This chapter assumes you know the basic Salesforce concepts (objects, fields, records), can find your way around Setup, and have a general idea of what a large language model does. You should also have met the idea of a topic and an action in earlier chapters. A little Flow or Apex knowledge helps but is not required.
Why inputs and outputs matter
When a customer says "Where is order 00012345?", the agent has to do three things with an action:
- Decide that the action fits the request.
- Fill each input from the conversation, or ask the customer for the missing value.
- Read the outputs and turn them into a reply.
The agent uses the text you wrote for the action, its inputs, and its outputs to do all three. Labels and descriptions are the only information it has. A vague description leads to wrong values, repeated questions, or an action that is never called.
What an input and an output are
An input is a value the action needs in order to run. An output is a value the action returns. Each one has these properties:
| Property | What it tells the agent | Example |
|---|---|---|
| Label | A short name for the value | Order Number |
| Description | What the value means and what format it takes | The order number the customer provided |
| Data type | The kind of value (text, number, Boolean, date, record) | Text |
| Required | Whether the action cannot run without it | Yes |
| Collect from user | Whether the agent should ask the customer for it | Yes |
| Show in conversation | Whether the output can appear in the reply | Yes |
The exact names and layout of these settings depend on the action type and the Builder release. Check the action's configuration panel in your org. The ideas below apply either way.
Where the definitions come from
You do not usually type inputs and outputs into Builder. They come from the underlying asset:
- Flow: the input and output variables marked "Available for input" and "Available for output".
- Apex: the
@InvocableVariablefields in the request and response classes. - Prompt template: the template's input resources.
- Standard action: the definition Salesforce ships.
Because of this, the best place to write good descriptions is in the source asset. A description written in Apex or Flow appears in Builder automatically. You can then adjust the wording in Builder if needed.
Writing a good label
A label names the value. Use the words a person would use, not a field's API name.
- Good:
Order Number - Weak:
ordNum - Weak:
Input1
The agent reads labels as language. A label such as Order Number already suggests where the value will come from in a conversation. A label such as varA suggests nothing.
Writing a good description
The description is the most important text on an input. A useful description answers four questions:
- What is this value?
- Where does it come from in the conversation?
- What format does it need?
- What should the agent do if it does not have it?
Compare these two descriptions for the same input:
| Weak | Strong |
|---|---|
| The order | The order number the customer provided, such as 00012345. Ask the customer if they have not given one. |
The strong version names the value, gives an example of the format, and says what to do when it is missing. Examples are useful for formats the agent could get wrong, such as dates, phone numbers, and IDs.
Descriptions for outputs
Output descriptions matter just as much. The agent decides what to say based on them. Say what the value means, list the possible values if there is a fixed set, and say how to read special values.
Label: Status
Description: Current status of the order. One of Draft, Activated, Shipped,
Delivered, or Cancelled. Returns "Not found" if no order matches the number.Listing the possible values lets the agent word the reply accurately. Naming "Not found" as a result lets a topic instruction handle it, which you will see below.
Required inputs and asking the customer
If an input is marked required, the agent will not call the action until it has a value. It gets that value in one of two ways:
- It finds the value in the conversation so far.
- It asks the customer.
Whether the agent may ask the customer is controlled by the input's collection setting. If you turn it off, the agent only uses values it already has. That suits inputs that come from context, such as the ID of the record the customer is viewing, and values you never want a customer to type.
Keep the number of required inputs small. Each extra required input is another question the customer has to answer before anything happens. If the action can work without a value, make it optional.
Choosing data types
Pick the narrowest type that fits.
- Use text for order numbers and other identifiers that can contain letters or leading zeros. Storing
00012345as a number would drop the zeros. - Use a Boolean for yes/no values.
- Use date or date/time for dates, so that the agent converts "next Friday" into a real date.
- Use a record or collection type only when the action truly works on whole records.
A wrong type is a common source of silent errors. The call may succeed with a wrong value, such as a missing leading zero, and you will only find out when a customer reports it.
Keeping outputs small
An action can return many values, but the agent reads all of them. Return only what a reply needs. Extra outputs add noise, and they raise the risk of sharing data the customer should not see.
Two habits help:
- Return a short status or result, not an entire record, when a status is all the customer asked for.
- Do not return fields that the current user should not see. Build the action so that field and object permissions are enforced.
In Apex this means running queries in user mode. The example below does that with WITH USER_MODE.
Example: an Apex action with described inputs and outputs
This invocable method looks up an order's status. Each input and output carries a label and a description, and those appear in Builder when you add the action to a topic.
public with sharing class GetOrderStatus {
public class Request {
@InvocableVariable(label='Order Number' description='The order number the customer provided' required=true)
public String orderNumber;
}
public class Response {
@InvocableVariable(label='Status' description='Current status of the order, or Not found')
public String status;
}
@InvocableMethod(label='Get Order Status' description='Looks up the status of an order by its order number')
public static List<Response> getStatus(List<Request> requests) {
List<Response> results = new List<Response>();
for (Request r : requests) {
Response res = new Response();
List<Order> orders = [
SELECT Status FROM Order
WHERE OrderNumber = :r.orderNumber
WITH USER_MODE
LIMIT 1
];
res.status = orders.isEmpty() ? 'Not found' : orders[0].Status;
results.add(res);
}
return results;
}
}Points to notice:
- The request and response are wrapped in classes, so each value gets its own label and description.
- The method takes a list and returns a list. Salesforce may pass several requests at once, so the method must return one response per request, in the same order.
- The
Not foundresult is part of the output contract. It is a documented value, not an exception.
Connecting outputs to topic instructions
Output descriptions and topic instructions work as a pair. The instruction decides what to do with each result, and the description tells the agent what results exist.
1. Ask the customer for their order number if they have not given one.
2. Use the Get Order Status action with that order number.
3. If the action returns 'Not found', tell the customer you could not find the order and ask them to check the number.
4. Otherwise, state the status in one sentence.Step 3 only works because the output description names the Not found value. If the description and the instruction use different wording, such as "No match" in one and "Not found" in the other, the agent may not connect them. Use the same words in both places.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| The agent asks for a value the customer already gave | The input description does not say where the value comes from | Add "the order number the customer provided" and an example |
| The agent invents a value | The input is optional or has no instruction for the missing case | Mark it required, or add "ask the customer if missing" |
| Leading zeros disappear | The input uses a number type | Change it to text |
| The reply ignores an error result | The output description does not name the error value | List the error value in the output description |
| The agent exposes too much data | The action returns more fields than needed, or ignores permissions | Return fewer outputs and enforce user mode |
| The wrong action is chosen | Two actions have similar labels and descriptions | Make each description say what the action does and does not do |
Testing your descriptions
After you change a description, test it in Builder with at least these conversations:
- The customer gives the value in the first message.
- The customer gives no value, so the agent must ask.
- The customer gives a value in the wrong format.
- The action returns the error result.
Check the reasoning view for each run. It shows which action the agent chose, which values it passed in, and what it received back. A wrong value at the input step points to the input description. A wrong reply after a correct output points to the output description or the topic instruction.
Summary of rules
- Give every input and output a plain-language label.
- Describe the meaning, the format, and an example for each input.
- Say what to do when a required value is missing.
- List the possible output values, including error results.
- Match the wording in outputs and topic instructions.
- Use the narrowest data type that fits.
- Return only what the reply needs, and enforce user permissions.
Exercise
An action called Check Warranty takes a serial number such as "SN-00871" and returns a coverage result. During testing, the agent keeps asking customers for their serial number even after they type it, and it sometimes replies as if coverage exists when the action returned "No record". List two changes you would make to the input and output descriptions.
Show answer
First, rewrite the input description to say where the value comes from and what it looks like, for example "The product serial number the customer provided, such as SN-00871. Ask the customer if they have not given one." Second, rewrite the output description to name every result, including "No record", and say what it means, for example "Coverage status: Active, Expired, or No record if the serial number is not in the system." Then add a topic instruction step that says what to tell the customer when the action returns "No record", using exactly that wording. Also confirm the serial number input is a text type, because a number type would break the "SN-" prefix.
Exercise
Why does the Apex example return one Response for every Request, in the same order, and why is "Not found" returned as a value and not thrown as an exception?
Show answer
Salesforce can pass several requests to an invocable method in one call, and it matches each response to its request by position, so the lists must line up. Returning "Not found" as a documented output value lets the output description and a topic instruction handle it with a specific reply. An exception would stop the action and leave the agent with a generic failure and nothing specific to say to the customer.