Sub topic 8
Returning useful results when something fails
Prerequisites and scope
This chapter assumes you can build an autolaunched flow with Get Records, Decision, and Update Records elements. You should also know how input and output variables work, and that the agent's language model reads their names and descriptions. The previous chapters covered how a flow becomes an action. This chapter covers what the agent receives when the flow does not go as planned.
By the end you should be able to do three things. You should be able to find where an action can fail. You should be able to add fault paths and error outputs. You should also be able to keep a failure from becoming a confusing or misleading reply to the customer.
Why failures matter more for agents
In a screen flow, a person sees an error message and decides what to do. In an agent action, the flow's outputs go to the language model, and the model writes the reply to the customer. The model can only work with what the flow returns.
Consider what happens in three cases:
- The flow throws an unhandled error. The agent gets a generic failure. It may apologize vaguely, retry with the same input, or invent an explanation.
- The flow finishes normally but returns an empty output. The agent may read the empty value as "no data" or may guess a value.
- The flow finishes normally and returns a clear message such as "No case was found with that number." The agent can pass this on and ask the customer to check the number.
The third case is the goal. Treat every failure as a result the agent can read, not as an event that stops the flow.
Kinds of failures to plan for
Not every failure is an error in the technical sense. Sort them into two groups.
| Kind | Example | How it shows up in Flow | How to handle it |
|---|---|---|---|
| Expected "no result" | The case number does not exist | Get Records finds nothing, and no error is raised | Decision element on the result, then set a message output |
| Bad input | Case number is blank or has the wrong format | The flow runs, but the value is unusable | Decision element before the data element |
| Data operation error | Update Records fails on a validation rule or a required field | A fault is raised on the element | Fault path on the element |
| Permission error | The running user cannot read or edit the object or field | A fault, or an empty result if the user cannot see the record | Fault path, plus a check of the run context |
| Limit or platform error | Too many queries, or a record lock | A fault, sometimes not recoverable | Fault path where possible, and keep the flow small |
The first two rows are the most common, and the flow does not report them as faults. Get Records returning zero rows is a normal outcome. If you do not check for it, the output variable stays at its default value, which is usually empty. The agent then gets an empty string and has no idea why.
Design an output contract
Before adding fault paths, decide how the flow reports success and failure. A simple and reliable pattern is to give every action the same two kinds of output:
- The data outputs, such as
caseStatus. - A message output, which always holds text the agent can use.
For the case lookup flow, one option is to have a single caseStatus output that holds either the status or a short message. That is what the topic's example does: its description says the value is "the current Status of the case, or a short message if no case was found."
A second option is to add a separate output. This is clearer when the agent needs to tell the difference, for example to decide whether to ask for the number again.
<variables>
<name>lookupSucceeded</name>
<dataType>Boolean</dataType>
<isCollection>false</isCollection>
<isInput>false</isInput>
<isOutput>true</isOutput>
<description>True if a case was found and its status was returned. False if the lookup failed for any reason.</description>
</variables>
<variables>
<name>errorMessage</name>
<dataType>String</dataType>
<isCollection>false</isCollection>
<isInput>false</isInput>
<isOutput>true</isOutput>
<description>A short plain-language explanation of why the lookup failed. Empty when lookupSucceeded is true.</description>
</variables>The trade-off is simple. One combined output is easy to configure but mixes data and messages. Separate outputs are clearer to the model but add more variables to describe. For small actions, the combined output is usually enough. For actions that change data, prefer a success flag, because the agent must not tell a customer that an update happened when it did not.
Build the flow step by step
The example below extends the case lookup flow. It has these elements, in order:
- A Decision named
Check_Inputthat tests whethercaseNumberis blank. - A Get Records element on Case, filtered on
CaseNumberequal tocaseNumber, storing only the first record, with a fault path. - A Decision named
Case_Foundthat tests whether the record variable is null. - Assignments that set the outputs for each branch.
Each failure branch ends in an assignment that sets the output. All branches reach the end of the flow. No branch leaves an output untouched.
Check input before using it
The agent can send a blank or badly formed value even when you mark the input as required in its instructions. Check it in the flow. The Decision on a blank caseNumber costs nothing and removes a whole class of confusing results.
Handle "no record found"
By default, Get Records stores nothing in the record variable when no row matches. It does not raise a fault. Add a Decision that checks whether the variable is null (in Flow Builder, use {!caseRecord} Is Null equals True). Do not skip this step and rely on a fault path, because a fault path will not run in this case.
Add a fault path
Data elements such as Get Records, Create Records, Update Records, and Delete Records can have a fault connector. To add one, select the element's lower edge in the canvas and choose Fault Path. Draw the fault connector to an Assignment that sets your error outputs, then connect that assignment to the end of the flow.
Without a fault path, the flow stops and the platform reports an unhandled error. The agent gets a failure with no useful message.
Inside the fault path, the resource $Flow.FaultMessage holds the system's error text. You can store it in a variable for logging. Be careful about passing it straight to the agent.
Write messages the agent can use
A good error message states what went wrong in plain words and, where possible, what the agent should do next. Compare these two values for errorMessage:
INVALID_FIELD: No such column 'Foo__c' on entity 'Case'The case could not be looked up right now. Do not guess a status. Offer to transfer the customer to a human agent.
The first is useful to a developer and meaningless to a customer. The second tells the agent what happened and what to avoid. Short instructions inside the message work because the model reads the output as text. Keep them factual and brief, and keep them consistent with the action instructions you write when you register the action.
Handle updates with extra care
Failures in actions that write data carry more risk. Suppose an action closes a case. If Update Records fails and the flow still returns "Done", the agent will tell the customer the case is closed.
Follow these rules for any action that changes data:
- Put a fault path on every Update Records, Create Records, and Delete Records element.
- Set a success output to
falseon the fault path andtrueonly on the final success branch. - Initialize the success variable to
falseat the start, using the variable's default value. Then a branch you forgot to wire cannot report success. - Validate before you write. Check status, ownership, or required values in a Decision rather than relying on a validation rule to reject the update.
- Avoid partial changes. If the flow updates two records and the second fails, the first change may stay in place unless the flow is designed to roll back. Keep write actions to one operation where you can.
Common mistakes
- Relying on the fault path for "not found." Get Records with no match does not fault. Add a Decision.
- Leaving outputs at their defaults on a failure branch. The agent then sees empty values. Assign every output on every branch.
- Returning raw system messages. These can expose internal names and confuse the customer.
- Reporting success by default. Start success flags at
false. - Fault paths that end without reaching the end of the flow. An unconnected branch can leave the flow in an unclear state. Connect every path.
- Messages the agent cannot interpret. Codes such as
ERR_17carry no meaning for the model unless the action instructions explain them. Use words.
Test the failure paths
Test each failure on purpose, not only the happy path. Chapter 12 covers testing tools in detail. For now, use these cases in Flow Builder's Debug mode:
- Run with a blank
caseNumber. Confirm that the blank-input branch sets the message. - Run with a number that does not exist, such as
99999999. Confirm that the not-found branch runs. - Run with a valid number. Confirm that the status output is set and the error output is empty.
- To force a fault, temporarily point a Get Records filter at a field the running user cannot read, or add a validation rule that rejects an update. Confirm that the fault path runs and that the message is safe.
For each run, check the output panel and confirm that every output has a value that makes sense.
Exercise
A flow looks up a case with Get Records and has a fault path on that element. A customer gives a case number that does not exist. The agent replies with an empty answer. Why did this happen, and how do you fix it?
Show answer
Get Records returns no rows without raising a fault, so the fault path never ran. The flow continued, and the output variable kept its empty default value. Add a Decision after Get Records that checks whether the record variable is null. On the "null" branch, assign a clear message such as "No case was found with that number" to the output, and make sure that branch reaches the end of the flow.
Exercise
An action updates a case's status. In the fault path, a developer assigns $Flow.FaultMessage to the output resultMessage and leaves the success flag unchanged. Name two problems and give a fix for each.
Show answer
First, the raw fault message may expose internal field names or record details, so replace it with a short, safe message and store the raw text in a log. Second, the success flag was never set on the fault branch. If it defaults to true or is set before the update, the agent may tell the customer the update worked. Initialize the flag to false at the start, set it to true only after the update succeeds, and set it to false explicitly on the fault path.