Branch workflow execution based on task outputs or workflow inputs using the conditional() construct.
Flytekit provides conditional as a first-class construct for selectively executing branches in a workflow. Conditions can test static values, workflow inputs, or outputs from upstream tasks.
Conditionals are restricted to binary and logical operators on primitive values. They are type-safe and highly performant because Flyte evaluates them without spawning additional pods.
Every conditional must be complete — all possible branches must be accounted for. If no branch matches, the workflow fails unless you provide .else_().fail(...) or a default .else_().then(...).
Conditionals use bitwise & and | instead of Python’s and / or. Due to Python’s PEP-335, and, or, and not cannot be overloaded. Flytekit follows the same convention used by pandas, numpy, and other libraries.
Use .is_true(), .is_false(), and .is_none() on promise values — unary operations are not supported directly:
@taskdef coin_flip(seed: int) -> bool: import random random.seed(seed) return random.random() > 0.5@workflowdef boolean_wf(seed: int = 42) -> float: result = coin_flip(seed=seed) return ( conditional("coin-flip") .if_(result.is_true()) .then(calculate_circle_circumference(radius=0.5)) .else_() .then(calculate_circle_area(radius=0.5)) )
Inside a workflow, inputs and outputs are automatically wrapped in a Promise object. This is why result has the .is_true() method — it is a Flytekit Promise, not a plain Python bool.