Switch Case
Route execution to one of several branches based on the value of an input.
Route workflow execution to one of several branches by matching an input value against a set of case values, similar to a switch-case statement in programming, enabling multi-way branching, value-based routing, and decision trees without chaining multiple Continue If blocks.
How This Block Works
This block compares a single input value against the keys of a case mapping and directs execution to the step associated with the first matching case. The block:
Takes a
valueinput (typically a selector referencing a workflow input or a step output, e.g. a classification result) and converts it to a stringLooks the string up in the
casesmapping, where each key is a case value and each value is the step to execute when that case matches (e.g.{"red": "$steps.on_red", "blue": "$steps.on_blue"})If
case_insensitiveis enabled, the comparison ignores letter caseIf a case matches, execution continues to that case's step and all other branches terminate
If no case matches, execution continues to the steps listed in
default_next_stepsIf no case matches and
default_next_stepsis empty, the branch terminates
Because the input value is converted to a string before matching, non-string values match their string representation: True matches the key "True", 1.0 matches "1.0" (not "1"), and a missing/None value matches "None". Each target step may appear at most once across cases and default_next_steps - to route several case values to the same logic, point each case at its own step or normalize the value upstream (e.g. with an Expression block).
Common Use Cases
Routing by classification result: Send images down different processing paths based on the top class predicted by a classification model (e.g. "damaged" → alert branch, "ok" → logging branch, anything else → default review branch)
Mode-based pipelines: Use a workflow input parameter (e.g.
$inputs.mode) to select between alternative processing branches at runtime without editing the workflowMulti-way alerting: Route to different notification blocks (email, Slack, webhook) depending on a severity or category value computed earlier in the workflow
Replacing chained conditions: Collapse a ladder of Continue If blocks comparing the same value against different constants into a single, easier-to-read block
Connecting to Other Blocks
This block controls workflow execution flow and can be connected:
After classification or detection blocks to branch on predicted classes, counts, or other prediction properties (often via a Property Definition or Expression block that extracts the value to switch on)
After workflow inputs to select a branch from a runtime parameter
Before any downstream blocks (models, notifications, sinks) that should only run for a specific case - each case target becomes the head of its own execution branch
With a default branch wired via
default_next_stepsto handle unmatched values, or left empty to simply stop when nothing matches
Type identifier
Use the following identifier in step "type" field: roboflow_core/switch_case@v1 to add the block as a step in your workflow.
Properties
Name
Type
Description
Refs
name
str
Enter a unique identifier for this step..
❌
value
Union[bool, float, int, str]
Value to match against the case keys. Typically a selector referencing a workflow input or a step output (e.g. $inputs.mode or $steps.classifier.top). The value is converted to a string before comparison, so booleans match keys 'True'/'False', 1.0 matches '1.0' and a None value matches 'None'..
✅
case_insensitive
bool
When enabled, case values are matched ignoring letter case (e.g. value 'RED' matches case key 'red')..
❌
The Refs column marks possibility to parametrise the property with dynamic values available in workflow runtime. See Bindings for more info.
Input and Output Bindings
The available connections depend on its binding kinds. Check what binding kinds Switch Case in version v1 has.
Input and output bindings
input
value(*): Value to match against the case keys. Typically a selector referencing a workflow input or a step output (e.g. $inputs.mode or $steps.classifier.top). The value is converted to a string before comparison, so booleans match keys 'True'/'False', 1.0 matches '1.0' and a None value matches 'None'..cases(step): Mapping of case value to the step that should execute whenvaluematches it, e.g. {"red": "$steps.on_red", "blue": "$steps.on_blue"}. Each target step may appear at most once acrosscasesanddefault_next_steps..default_next_steps(step): Steps to execute when no case matches. Leave empty to terminate the branch when nothing matches..
output
Last updated
Was this helpful?