Skip to content
Notifications
Clear all

Guide: Avoiding common pitfalls with the 'if/else' node - conditional logic examples

1 Posts
1 Users
0 Reactions
5 Views
(@kubernetes_tinker_99)
Estimable Member
Joined: 4 months ago
Posts: 56
Topic starter   [#9939]

Hey folks! 👋 I've been tinkering with Relevance AI's workflows for a few months now, mostly to automate some of our internal K8s and Argo CD notification pipelines. One node that seems simple but can quickly get tangled is the humble **'if/else' node**. It's powerful, but I've seen (and made!) some classic mistakes that lead to workflows dying silently or taking weird branches.

Here’s a quick guide on patterns that work and what to watch out for.

### The Big Gotcha: Your Condition Needs a Boolean
The most common pitfall is feeding the node something that isn't explicitly `true` or `false`. The condition field needs to evaluate to a boolean. Don't just drop a value in there.

**❌ Don't do this:**
```json
{
"condition": "{{workflow.inputs.user_tier}}",
"true_path": "premium",
"false_path": "standard"
}
```
If `user_tier` is the string `"premium"`, this will likely go down the `false_path` because a non-empty string is often truthy in JS, but the node might interpret it as `false` if it's not a strict boolean.

**✅ Do this instead:**
Use a comparison operator to *create* a boolean.
```json
{
"condition": "{{workflow.inputs.user_tier == 'premium'}}",
"true_path": "handle_premium",
"false_path": "handle_standard"
}
```

### Nesting? Use Multiple Nodes
Trying to build a complex `if/else if/else` chain inside a single node's condition logic gets messy fast. It's clearer and more debuggable to chain nodes.

For example, checking a deployment status:
* First `if/else`: `{{workflow.inputs.environment == 'production'}}`
* On `true`, route to a node that checks `{{workflow.inputs.approved == true}}`
* On `false`, route to your staging branch.

This makes each decision point visible in the execution graph, which is a lifesaver when debugging.

### Keep Conditions Readable
If your condition logic gets long, use the **Custom Code** node *before* the `if/else` to compute a clean boolean result. Store it in `steps.my_custom_node.output.result` and then your `if/else` condition becomes just `{{steps.my_custom_node.output.result}}`.

Example: Instead of a monster condition checking multiple array elements and string lengths, compute `is_valid_request` in a prior step.

What other conditional logic headaches have you run into? Any clever patterns for handling edge cases in your AI workflows?


#k8s


   
Quote