decide
decide
Conditional branching within a machine’s execution flow. A decide step evaluates one or more conditions using when/otherwise clauses and routes execution accordingly. Each branch can contain inline steps, return a value as an expression, or dispatch to a named flow with run.
When to use
Use decide when you need to:
- Route execution based on a previous step’s output
- Choose between different processing paths
- Guard downstream steps based on conditions
- Implement if/else or multi-branch logic
Use compute with ternary expressions for simple value selection. Use match for pattern matching against specific values. Use ask ... using when the branching decision requires LLM judgment rather than deterministic rules.
Syntax
decide <name> when <condition> <steps or expression> when <condition> <steps or expression> otherwise <steps or expression>Conditions are evaluated top to bottom. The first when clause whose condition is true executes. If no condition matches, the otherwise clause runs. If there is no otherwise and no condition matches, the step returns null.
Each branch can contain:
- A single expression (the branch’s return value)
- One or more steps (the last step’s output becomes the branch value)
- A
run flow(name)directive to dispatch to a named flow
Condition expressions
Conditions use the same expression language as compute steps. Both symbolic and natural-language operators work:
| Symbolic | Natural language | Meaning |
|---|---|---|
== | is | Equality |
!= | is not | Inequality |
> | is greater than | Greater than |
< | is less than | Less than |
>= | is at least | Greater or equal |
<= | is at most | Less or equal |
&& | and | Logical AND |
|| | or | Logical OR |
! | not | Logical NOT |
Examples
Simple two-way branch
machine ticket_router accepts priority as text, is required
responds with queue as text
implements decide route when input.priority is "urgent" {queue: "critical"} otherwise {queue: "standard"}Multi-condition routing with step results
machine approval_workflow accepts amount as number, is required department as text, is required
responds with approved as boolean approver as text
implements ask evaluate, using: "anthropic:claude-haiku-4" with task "Evaluate this expense request for risk. Amount: ${input.amount}, Department: ${input.department}" returns risk_level as text justification as text assuming risk_level: "low" justification: "Standard operating expense"
decide route_approval when input.amount is greater than 10000 {approved: false, approver: "CFO review required"} when steps.evaluate.risk_level is "high" {approved: false, approver: "Risk committee"} when input.amount is at most 500 {approved: true, approver: "auto-approved"} otherwise {approved: true, approver: "manager"}Branching to named flows
machine order_processor implements compute check_inventory {in_stock: input.quantity <= 100}
decide fulfillment_path when check_inventory.in_stock run flow(ship_direct) otherwise run flow(backorder)
flows flow ship_direct action create_shipment call machine: "@mashin/actions/shipping/create" items: input.items compute result {status: "shipped", tracking: create_shipment.tracking_id}
flow backorder action notify_warehouse call machine: "@mashin/actions/notifications/send" message: "Backorder needed for order " + input.order_id compute result {status: "backordered", tracking: null}Natural language conditions
decide escalation when steps.sentiment.score is less than 0.3 and input.is_vip {action: "escalate_immediately", reason: "Unhappy VIP customer"} when steps.sentiment.score is less than 0.5 {action: "flag_for_review", reason: "Low satisfaction detected"} otherwise {action: "continue", reason: "Customer is satisfied"}Governance
Decide steps are pure control flow (Inv 5: Control-Flow Observability). They evaluate conditions and route execution but perform no I/O themselves. Every branch decision is recorded as a first-class step event in the behavioral ledger, including:
- The condition digest (which condition was evaluated)
- The selected branch (which
whenclause orotherwisefired) - The inputs to the condition expression
This means decide steps:
- Never require governance approval on their own
- Are always observable in execution traces
- Make branching logic auditable after the fact
Steps inside branches inherit normal governance. An ask step inside a when clause still requires reason capability and goes through the governance interpreter.
Translations
| Language | Keyword |
|---|---|
| English | decide |
| Spanish | decide |
| French | decide |
| German | entscheidet |
| Japanese | 判断 |
| Chinese | 判断 |
| Korean | 결정 |
See also
- compute - For simple conditional values using ternary expressions
- run - Execute a named flow (used inside decide branches)
- implements - The section where decide steps live
- ask … using - When the decision requires LLM judgment