Classify an Error as Retryable
Problem Statement
Decide whether a failed tool call should be retried based on its HTTP-style status code. Transient failures are worth retrying; client errors are not.
Background
By convention, 429 (rate limited) and any 5xx (server error) are retryable. 4xx other than 429 are client errors and are not retryable. Anything below 400 is a success and needs no retry.
Your Task
Implement:
def is_retryable(status):
Return True if status is 429 or in [500, 599], else False.
Input Format
- status (int): the status code.
Output Format
- A boolean.
Sample
print(is_retryable(503))
Output:
True
Example
print(is_retryable(503))
True
- The input status code is , which is passed to the classification logic to determine if it represents a transient failure.
- The function first checks if the status is exactly (rate limited); since , this condition evaluates to false.
- Next, it checks if the status falls within the server error range ; since , this condition evaluates to true.
- Because the status satisfies the server error criterion, the overall retryability check returns true, indicating the call should be retried.
- The final output is True
Constraints
- Retryable:
status == 429or500 <= status <= 599. - All other codes are non-retryable.
- Return a bool.