Sub topic 10
Describing action inputs and outputs
This chapter assumes you know what a topic and an action are, and that you can read basic Flow or Apex. It covers how to describe the values an action takes in and sends back, so the agent can fill them and use them correctly.
Why descriptions matter
An agent does not read your Flow or Apex code. It sees the action's name, its description, and the label and description of each input and output. From that text it decides what to pass in and how to read what comes back.
If a description is vague, the agent guesses. A variable called val1 with no description may get the wrong value, or no value at all.
Inputs
An input is a value the action needs before it can run. For each input, set these properties:
- Label: a short, human-readable name, such as "Order Number".
- Description: what the value is and where it comes from, such as "The order number the customer provided".
- Required: whether the action cannot run without it.
When an input is required and the customer has not supplied it, the agent asks for it. When an input is optional, the agent may leave it empty. Mark an input as required only if the action truly fails without it.
Outputs
An output is a value the action returns. The agent reads outputs to write its reply, so describe what each one means and what special values to expect.
For example, an output named "Status" should say that it holds the current order status, and that it returns "Not found" when no order matches. The agent can then handle that case, as long as your topic instructions also say what to do with it.
A worked example
The invocable Apex method from this tutorial shows all of these properties in code. Each @InvocableVariable carries the label, description, and required flag that Builder shows to the agent.
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;
}
}The input is required, so the agent will ask for an order number if the customer has not given one. The output description names the "Not found" value, which lets a topic instruction refer to it directly.
In a Flow, you set the same properties on the Flow variables. A variable must be marked "Available for input" or "Available for output" before it appears as an action input or output.
Common errors
| Problem | Effect | Fix |
|---|---|---|
| No description on an input | Agent passes a wrong or empty value | Say what the value is and where it comes from |
| Generic labels such as "Input 1" | Agent cannot tell inputs apart | Use specific labels such as "Order Number" |
| Special output values not described | Agent does not know what "Not found" means | Name the value in the output description |
| Everything marked required | Agent keeps asking questions the action does not need | Require only what the action must have |
| Output not needed by the agent | Extra values can clutter reasoning | Return only what the reply needs |
Check your understanding
Exercise
An action input called "Case ID" has no description. In testing, the agent sometimes passes the customer's name instead of the case number. What should you change, and why?
Show answer
Add a description that states what the value is, for example "The case number the customer provided, such as 00001234". Also give it a clear label. The agent chooses input values from the label and description, so without them it guesses. If the action cannot run without it, mark the input as required so the agent asks the customer for it.
Exercise
Your action returns the text "Not found" when no record matches. Where should you document this, and what else should you update?
Show answer
Document it in the output's description, for example "Current status of the order, or Not found". Then add a step to the topic instructions that tells the agent what to do when the output is "Not found", such as asking the customer to check the number.