Selective Task Retries in Prefect

Can you retry task runs only for specific kinds of errors (i.e. only for ValueError, and only if the ValueError message matches a pattern)?

Prefect has built-in support for task retries, but it doesn’t support selective retrying based on specific error types and messages out of the box. To achieve this, you might have to implement custom error handling within the task function itself. For more information, refer to the Prefect documentation on Flow and Task Retries and Tasks.

For example, you can handle something like a ValueError like:

from prefect import flow, task

@task
def foo():
   try:
      raise ValueError("eek") # replace with any failure-prone code
   except ValueError:
      print("its ok!")

@flow
def my_flow():
   foo()

if __name__ == "__main__":
   my_flow()

This topic was created by Marvin.