Skip to navigation
Messaging

goto

View as MarkdownOpen in Claude

Jump to a label within the current section. Used for retry loops and conditional repetition.

goto does not cross subroutine boundaries — it can only jump within the section that contains the matching label.

Properties

goto
string | objectRequired

Either a label name (shorthand) or an object that accepts the properties below. The shorthand jumps to the label exactly as written, without variable expansion, with the default max of 100.

goto.label
stringRequired

Label to jump to. Must reference a label step earlier or later in the current section.

goto.max
integer | stringDefaults to 100

Maximum number of jumps to label. Accepts an integer or a %{...} variable reference, such as %{params.max_retries}; a reference is expanded and then converted to an integer. A reference that doesn’t resolve allows no jumps — it does not fall back to 100.

Jumps are counted per target label for the whole run, not per goto step. Every goto that targets the same label name shares one count, including goto steps in other sections and in documents reached through execute or transfer. Each jump attempt adds one to the count and is allowed while the count is at most this step’s max.

When an attempt exceeds max, the jump doesn’t happen and the steps array that contains the label ends without running its remaining steps. Execution continues with whatever ran that array, such as the caller of an execute. A goto inside a switch case that targets a label in the enclosing section ends that section; a label inside the same case array ends only the case, and the steps after the switch still run.

max cannot raise the document’s limit of 100 steps, which counts every step including each label passed. That limit can stop execution before max jumps are reached. If the limit is reached on the goto step itself, the jump never happens and the run ends with a swml_goto_label_not_found error.

Examples

Retry a request up to three times

version: 1.0.0
sections:
main:
- label: try_lookup
- request:
url: "https://api.example.com/lookup"
body:
phone: "%{message.from}"
save_variables: true
- switch:
variable: request_result
case:
success:
- reply:
body: "Hi %{request_response.name}!"
timeout:
- goto:
label: try_lookup
max: 3
default:
- reply:
body: "Sorry, we couldn't look up your account."

Read the retry limit from a variable

version: 1.0.0
sections:
main:
- execute:
dest: lookup
params:
max_retries: 2
- reply: "Lookup finished with result: %{request_result}"
lookup:
- label: try_lookup
- request:
url: "https://api.example.com/lookup"
body:
phone: "%{message.from}"
- switch:
variable: request_result
case:
timeout:
- goto:
label: try_lookup
max: "%{params.max_retries}"
default: []

Jump forward with the shorthand

version: 1.0.0
sections:
main:
- switch:
variable: message.body
transform: lowercase_trim
case:
help:
- goto: help
default: []
- reply: "Thanks for your message!"
- return: null
- label: help
- reply: "Reply STOP to unsubscribe."