TECHNOLOGY

Prefect retry conditions filter failed task attempts

In this article
THE QUICK TAKE

A retry condition filters failures within the configured retry budget; it does not make ordinary negative business output into a failed task.

Classify the failure before spending another attempt

A document-fetch task can fail because its service is temporarily unavailable or because the requested identifier is invalid. Repeating those cases has different value. Prefect’s retry guide provides retry_condition_fn for deciding dynamically whether another attempt is appropriate. Begin with the failures the application can actually distinguish, rather than treating every unsuccessful document request as the same transient event.

Read the callback’s failure state

The task reference describes a callback receiving the task, task run and state. The state carries the failure being considered. The guide demonstrates examining an exception obtained from that state and returning a Boolean decision. Define which error classes are retryable in this application’s environment. An absent document may be permanent in an immutable catalog but temporary during an explicitly documented indexing delay.

Keep eligibility separate from the remaining budget

The current task engine requires both remaining retries and a permitting condition. Returning true cannot replenish an exhausted budget. Returning false can stop further attempts while budget remains. Delay and jitter configure timing after eligibility is established. This separation lets a reviewer understand whether execution ended because the error was excluded or because the allowed attempts had already been consumed.

Do not conceal failure inside ordinary output

A plain result describing an unsupported document is a business outcome unless the task deliberately represents it through a failure mechanism. The condition is not a general validator that scans every returned dictionary for unhappy wording. Choose whether unsupported input should end normally with an explicit rejection or should fail the workflow. Task contracts help make that distinction visible to the downstream consumer before retry rules are added.

Keep the predicate simple enough to trust

The engine catches an exception raised inside the retry-condition check, logs it and declines the retry. A broken predicate can therefore remove the recovery opportunity it was intended to control. Use a small, explicit classification and preserve the original error alongside the predicate decision. Tool observations should show actual attempts and their outcomes, so a final failure is explainable without inferring retry behavior from a configured count alone.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles