acoustic-parrot-22802
06/10/2025, 6:14 AMjolly-florist-66728
06/10/2025, 6:14 AMconditional
construct. Define tasks a, b, c, d, e, and use a conditional in your workflow to execute c only if the input string is not None; otherwise, skip c. Note that Flyte requires both if and else branches in conditionals, so you can use an "echo" or noop task in the else branch to effectively skip execution (Flyte conditionals guide, noop/echo pattern).
Here is a minimal example:
import flytekit as fl
from flytekit.core.task import Echo
echo = Echo(name="echo", inputs={"x": str})
@fl.task
def a(): ...
@fl.task
def b(): ...
@fl.task
def c(x: str): ...
@fl.task
def d(): ...
@fl.task
def e(): ...
@fl.workflow
def wf(x: str = None):
a()
b()
conditional_result = (
fl.conditional("run_c")
.if_(x.is_not_none())
.then(c(x=x))
.else_()
.then(echo(x=x))
)
d()
e()
Would you like a step-by-step explanation or more details?
Sources:
- Flyte conditionals guide
- noop/echo pattern š 0 button š 0 button š” Hint: Mention @runllm in the thread for followups.acoustic-parrot-22802
06/10/2025, 7:20 AMacoustic-parrot-22802
06/10/2025, 7:24 AMjolly-florist-66728
06/10/2025, 7:24 AM