Zelaxy
ZelaxyDocs
Core Blocks
Block

Switch Block

Deterministic multi-branch routing with multiple match modes

Switch Block

The Switch block routes workflow execution to one of multiple paths based on value matching — similar to JavaScript's switch statement. Unlike the Router block (which uses an LLM), Switch is deterministic, fast, and free — no AI calls needed.

Overview

PropertyValue
Typeswitch
CategoryCore Block
Color#8B5CF6 (Purple)

When to Use

  • You need to branch on a known set of values (status codes, categories, types)
  • You want deterministic routing without LLM cost or latency
  • You need multi-way branching (more than true/false)
  • You're routing based on API response fields, user selections, or computed values
  • You need pattern matching (contains, starts with, regex) or numeric comparisons

Switch vs Router vs Condition

FeatureSwitchRouterCondition
MethodMulti-mode value matchLLM selectionBoolean expression / LLM judge
BranchesUnlimitedUnlimited2 (true/false)
SpeedInstantSlow (LLM call)Fast (expression) or Slow (LLM)
CostFreeToken costFree (expression) or Token cost
Best forKnown values / patternsSemantic routingConditional logic

Configuration

Switch Value

The value to match against. Supports {{}} block references:

{{agent.status}}
{{api.response.category}}
{{starter.input}}

Match Mode

Controls how the switch value is compared against each case. Select from the dropdown:

ModeDescriptionExample
Exact MatchCase-sensitive exact string comparison (default)"pending" matches "pending"
ContainsCase-insensitive substring search"Hello World" matches case "world"
Starts WithCase-insensitive prefix check"order-123" matches case "order"
Ends WithCase-insensitive suffix check"file.pdf" matches case ".pdf"
RegexRegular expression pattern match (case-insensitive)"abc-123" matches case "^[a-z]+-\d+$"
NumericNumeric comparison with operators (>, <, >=, <=, ==, !=)Input "75" matches case ">= 50"

Cases

Define one or more cases, each with a match value. Add cases dynamically using the + Add Case button. Each case creates a separate output connection handle.

Case values support {{}} variable references — type {{ in a case value input to see a dropdown of available variables from upstream blocks.

A default case is always present and catches any value that doesn't match a defined case.

SettingDescription
Case ValueThe string/pattern to match against the switch value (supports {{}} references)
DefaultCatches all unmatched values (always present, cannot be removed)

Outputs

FieldTypeDescription
matchedValuestringThe value of the matched case
selectedCaseIdstringInternal ID of the matched case
matchModestringThe match mode that was used
selectedPathjsonInformation about the selected path (blockId, blockType, blockTitle)
inputValuestringThe original input value (trimmed)

Examples

Order Status Router (Exact Match)

Goal: Route order processing based on status field.

Workflow:

[Starter] → [API: Get Order] → [Switch] → [Agent: Process] (status = "pending")
                                         → [Slack: Notify] (status = "shipped")
                                         → [Gmail: Alert] (status = "cancelled")
                                         → [Response: Unknown] (default)

Configuration:

  • Switch Value: {{api.status}}
  • Match Mode: Exact Match
  • Cases:
    • Case 1: pending
    • Case 2: shipped
    • Case 3: cancelled
    • Default: catches everything else

File Type Router (Ends With)

Goal: Route file processing based on extension.

Configuration:

  • Switch Value: {{starter.filename}}
  • Match Mode: Ends With
  • Cases:
    • .pdf → PDF processor
    • .csv → CSV parser
    • .json → JSON handler
    • Default → Unsupported format response

Score Grading (Numeric)

Goal: Grade a numeric score into categories.

Configuration:

  • Switch Value: {{api.score}}
  • Match Mode: Numeric
  • Cases:
    • >= 90 → A grade handler
    • >= 80 → B grade handler
    • >= 70 → C grade handler
    • Default → Failing grade handler

In numeric mode, cases are evaluated top to bottom — the first matching case wins. Order your cases from most specific to least specific.

Content Filter (Regex)

Goal: Route content based on pattern matching.

Configuration:

  • Switch Value: {{agent.output}}
  • Match Mode: Regex
  • Cases:
    • ^error: → Error handler
    • \b(urgent|critical)\b → Priority handler
    • ^success → Success handler
    • Default → General handler

Language Router (Exact Match with Variables)

Goal: Route content to language-specific processors using dynamic case values.

Configuration:

  • Switch Value: {{starter.language}}
  • Match Mode: Exact Match
  • Cases:
    • en → English pipeline
    • es → Spanish pipeline
    • fr → French pipeline
    • Default → Fallback translation pipeline

Tips

  • Exact Match is case-sensitive; Contains, Starts With, Ends With, and Regex are case-insensitive
  • Non-string values are converted to strings before matching
  • Input values are whitespace-trimmed before comparison
  • Case values support {{}} variable references — resolved at execution time
  • If no case matches and the default case has no connection, the block will error
  • In Numeric mode, use operators like > 100, <= 50, != 0, or just a plain number for exact comparison
  • In Regex mode, invalid patterns are treated as non-matching (no error thrown)
  • Cases are evaluated top-to-bottom — the first match wins (like JavaScript's switch)
  • Use the Router block if you need semantic/fuzzy matching via LLM