Conditional Workflows
Conditional workflows branch to different nodes based on data in the workflow state. This allows a single workflow to handle multiple cases without building separate workflows for each.
8 min•By Priygop Team•Updated 2026
Conditional Branching
Conditional Branching
# Conditional workflow: different paths for different customers
def classify_customer_node(state: dict) -> str:
"""Classify customer and decide the path."""
order_total = state["input"].get("order_total", 0)
account_age_days = state["input"].get("account_age_days", 0)
previous_disputes = state["input"].get("previous_disputes", 0)
# VIP: high value + long-standing + no dispute history
if order_total > 500 and account_age_days > 365 and previous_disputes == 0:
state["data"]["customer_tier"] = "vip"
return "vip"
# New customer: account less than 30 days
elif account_age_days < 30:
state["data"]["customer_tier"] = "new"
return "new"
# High risk: multiple dispute history
elif previous_disputes >= 3:
state["data"]["customer_tier"] = "high_risk"
return "high_risk"
# Standard
else:
state["data"]["customer_tier"] = "standard"
return "standard"
def vip_fast_track_node(state: dict) -> str:
"""VIP customers get automatic refund with no approval."""
print(f" VIP fast-track refund approved")
state["data"]["refund_status"] = "auto_approved"
return "success"
def standard_review_node(state: dict) -> str:
"""Standard customers go through normal review."""
print(f" Standard review initiated")
state["data"]["refund_status"] = "pending_review"
return "pending"
def high_risk_escalate_node(state: dict) -> str:
"""High-risk customers require manager approval."""
print(f" High-risk escalation to manager")
state["data"]["refund_status"] = "escalated"
return "escalated"
# Test all branches
for case in [
{"order_total": 600, "account_age_days": 400, "previous_disputes": 0},
{"order_total": 50, "account_age_days": 15, "previous_disputes": 0},
{"order_total": 200, "account_age_days": 200, "previous_disputes": 4},
]:
state = {"input": case, "data": {}}
tier = classify_customer_node(state)
print(f" Tier: {state['data']['customer_tier']} → branch: {tier}")