Return
The Return expression signals the end of a compound action’s execution, streaming mapped data back to the chat for user-layer runs. In system-layer runs, it will stop quietly, and any returned data is sent to the caller. The expression also works as an early-return expression, you can place it at the end of the flow or in a Switch case to simplify logic.
Unlike an error-based exit (handled by a raise expression), the return expression exits gracefully, providing a way to output data in a structured format using the output_mapper, which is a data mapper. The full syntax is in the Data Mapper Reference.
How Return ends a compound action
Returning from inside a loop
A return placed inside a for loop breaks out of the loop. The current iteration stops at the return, no further iterations run, and the compound action ends with the data you mapped. This lets you stop a loop as soon as you find what you are looking for, instead of iterating through the whole list.
User-layer and system-layer runs
- Be mindful of our token limits.
- Return statements have some reserved keywords for Citations (
results&result). Please do not use the keyword “result” unless you plan to include an “id” and “friendly_id” (optional) which will create a citation.
Low-code editor
In the compound action editor, select + and then Return to add the step. Select the step to open the Return Step panel.
- Map the Data: In Output Mapper, build the object the compound action returns. Each key is a field in the result; each value reads the data bank or is a quoted constant.
- Leave Early: Put a Return step inside a Switch case to stop the compound action as soon as that case matches.
In this example, next_step: "'Show book recommendations'" returns fixed text, because the inner quotes make it a constant. request_type: data.request_type returns a value from the data bank.
Syntax reference
Schema
Fields
Practical examples
Return the results of two actions
Return the aggregated result of two actions
Compound action
Expected result
Return a transformed user list
Transform a list of users
Compound action
Data bank
Expected result
Return early from a Switch case
Skip approval process if user is admin
Return early from a for loop
Breaking out of the loop is not the same as continuing after it. A return inside a for loop ends the entire compound action, whether or not expressions follow the loop. Any step placed after the loop is skipped.
Stop looping as soon as a matching ticket is found
The loop checks one ticket per iteration. The first time a ticket is open, the return exits both the loop and the compound action, so the remaining ticket IDs are never fetched and notify_no_open_tickets never runs. If no ticket matches, the loop completes normally and execution continues with the step after the loop.