I have a requirement like ,,,, I have T1 -> T...
# ask-ai
a
I have a requirement like ,,,, I have T1 -> T2 ->T3 I want to execute T3 only when T2's output is True any idea how can we do this > @ancient-wolf-19325
a
You can achieve this in Flyte by using the conditional construct. Define T1 and T2 as tasks, then use a workflow with a conditional to execute T3 only if T2's output is True. The conditional block evaluates T2's output and runs T3 in the then branch; otherwise, you can specify an alternative action or simply skip T3. Example:
Copy code
from flytekit import task, workflow, conditional

@task
def T1() -> int:
    # your logic
    return 1

@task
def T2(x: int) -> bool:
    # your logic
    return x == 1

@task
def T3() -> str:
    return "T3 executed"

@workflow
def my_wf() -> str:
    t1_out = T1()
    t2_out = T2(x=t1_out)
    return (
        conditional("run_t3")
        .if_(t2_out.is_true())
        .then(T3())
        .else_()
        .then("T3 skipped")
    )
This pattern is the recommended way to branch workflow execution based on a task's output in Flyte. For more, see the Flyte conditionals documentation. Would you like more detail or explanation? Sources: - Flyte conditionals documentation - Flyte conditionals example 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.