Switch
Description
The Switch node is a conditional router. It receives text on its single input anchor and evaluates it against a list of user-defined conditions (cases). The text is routed to the output anchor corresponding to the first matching case. If no conditions match, the text is sent to the final "Default" output.
It is the primary tool for creating branching logic in a workflow (e.g., "if the AI says 'error', go to branch A; otherwise go to branch B"). The number of output anchors is automatically determined by the number of cases defined in the configuration.
Configuration Properties
🔀 Test Mode Section
Radio Buttons
Selects the type of evaluation to perform on the incoming text. Changing this mode updates the available configuration fields below it.
TextPattern
Tests if the text contains a specific substring or matches a Regular Expression.
- Pattern: The text or regex to search for.
- Use Regex: If checked, the pattern is treated as a Regular Expression. If unchecked, it is a simple case-insensitive substring search.
NumericComparison
Attempts to parse the incoming text as a number (Double) and compares it to a reference value.
- Numeric Operator: The comparison operator (Greater than, Less than, Equal, Greater than or equal, Less than or equal).
- Numeric Value: The reference number to compare against. Note: If the incoming text cannot be parsed as a number, this test fails immediately and the node moves to the next case.
TextLength
Evaluates the length (number of characters) of the incoming text string.
- Numeric Operator: The comparison operator (same as above).
- Numeric Value: The reference length to compare against.
Similarity
Calculates a similarity percentage between the incoming text and a reference text using the Levenshtein distance algorithm.
- Similarity Source: The reference text to compare against.
- Numeric Operator: Typically used with "Greater than" to check if similarity exceeds a threshold (e.g., > 80%).
- Numeric Value: The threshold percentage (0-100).
📋 Cases Section
List Box
Displays the list of defined conditions. Each item represents one output anchor (except the last one).
- The list is evaluated from top to bottom.
- The last item in the list is always the Default case (
Default — no condition matches). It acts as a catch-all if no other conditions are met. - You can select a case in the list to edit its parameters in the sections above.
🔘 Action Buttons
Add
Adds a new case to the list. This creates a new output anchor on the node. The new case is initialized with the currently selected Test Mode and default values.
Remove
Deletes the currently selected case from the list. This removes the corresponding output anchor. The Default case cannot be removed (it is always present).
Apply
CRITICAL: Saves the current settings (Test Mode, Pattern, Operator, Value, etc.) to the currently selected case in the list.
- You MUST click Apply after editing a case to commit the changes.
- If you edit the fields but click OK without clicking Apply, your changes will be lost.
- If you select a different case in the list without clicking Apply, your unsaved changes may be discarded.
Usage Example
"Routing AI responses based on sentiment":
- An Agent node generates a response.
- A Switch node with 3 cases:
- Case 1:
TextLength> 100 (Long response) → Output 0 → File Write (save to log). - Case 2:
TextPatterncontains "error" (Error detected) → Output 1 → Agent (retry logic). - Case 3 (Default): → Output 2 → Output (display to user).
- Case 1:
- The Switch node evaluates in order. If the response is short and contains no error, it falls through to the Default case.
⚠️ Pitfalls to Avoid
The "Apply" Button Trap: This is the most common mistake. The configuration dialog does not auto-save changes as you type. You must explicitly click Apply to update the selected case in the list. If you forget this step and click OK, the node will retain its old configuration.
Order of Evaluation: The node stops at the first match. If you have a broad condition (e.g., TextLength > 0) at the top of the list, it will catch everything, and subsequent cases will never be reached. Always place specific conditions at the top and broad conditions at the bottom.
Numeric Parsing Failures: If you use NumericComparison but the incoming text is not a valid number (e.g., "Hello"), the comparison fails instantly. The node does not crash; it simply treats it as a "no match" and moves to the next case or the Default output.
Similarity Source Empty: If you use the Similarity mode but leave the Similarity Source textbox empty, the comparison will likely fail or return 0% similarity. Always ensure a reference text is provided.
Default Case is Mandatory: You cannot delete the last item in the list. The node always requires a fallback path. If you want to "block" execution when no conditions match, you can route the Default output to a dead-end or a specific error-handling node.
Regex Syntax: If Use Regex is checked in TextPattern mode, ensure your pattern is valid. An invalid regex will cause the test to fail (and potentially throw an error depending on implementation), routing the text to the next case.