<@U06RKAMK0UC> can I set the status of a specific ...
# ask-ai
b
@ancient-wolf-19325 can I set the status of a specific workflow to failed based on the output from a task?
j
Reasoning Complete! 🤖 🔍 Searched knowledge base: I'll look up whether you can automatically set a workflow's status to 'failed' depending on a task's output, and if so, how to do it. • Searching over 10 data sources from the following: File, Github File, Github Issue, Web • Found 61 documents that could be relevant from the following data sources: Github File, Github Issue, Github Pull Request, Web Content. • Filtered down to the top 30 most relevant documents. ✍️ Generated answer: I've confirmed that Flyte doesn't have a built-in way to set a workflow to 'failed' just based on a task's output. Instead, you can raise an exception in your task or use conditional logic in your workflow to explicitly fail it if certain output values are detected.
You cannot directly set the status of a Flyte workflow to failed from within a task based on its output. Workflow status is determined by the success or failure of its nodes (tasks, subworkflows, etc.), and Flyte does not provide an explicit API to programmatically set the workflow status from inside a task. However, you can design your workflow so that if a task returns an output indicating failure, you raise an exception in a downstream node or use conditionals to trigger a failure, which will cause the workflow to fail accordingly. If you want to execute custom logic on failure (e.g., cleanup), you can use the failure node feature by specifying an
on_failure
handler in your workflow, but this does not allow you to arbitrarily set the workflow status; it only reacts to actual failures in execution. For more, see the failure node documentation and workflow basics. Would you like more detail or example code for handling this pattern? Sources: - failure node documentation - workflow basics 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
b
Can you give me an example of using failure node
@ancient-wolf-19325 Can you give me an example of using failure node
j
Reasoning Complete! 🤖 🔍 Searched knowledge base: I'll look up a concrete example of how to use a failure node in a Flyte workflow, so you can see exactly how it's implemented. • Searching over 10 data sources from the following: File, Github File, Github Issue, Web • Found 50 documents that could be relevant from the following data sources: Github File, Github Issue, Github Pull Request, Web Content. • Filtered down to the top 30 most relevant documents. ✍️ Generated answer: I have the details needed to show you a clear example of how to use a failure node in a Flyte workflow, including how to set it up and what the handler looks like.
Yes. To use a failure node in Flyte, define a cleanup task and set it as the
on_failure
handler in your workflow. The failure node will execute if any task in the workflow fails. The cleanup task's inputs must match the workflow's inputs, and it can also accept an
err
parameter for the error message. This feature is available in Flyte 1.10.7 and later. See the official example:
Copy code
from flytekit import task, workflow

@task
def clean_up(name: str, err: str = None):
    print(f"Cleaning up {name} due to error: {err}")

@task
def will_fail(name: str):
    raise Exception("Intentional failure")

@workflow(on_failure=clean_up)
def my_wf(name: str):
    will_fail(name=name)
If
will_fail
fails,
clean_up
will be executed automatically. Would you like a more detailed breakdown or explanation? Sources: - failure node documentation 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.