> ## Documentation Index
> Fetch the complete documentation index at: https://docs.learningcommons.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Error handling

> The Python SDK provides specific error types to help you handle different scenarios.

The SDK provides specific error types to help you handle different scenarios.

```python example.py theme={null}
import time
from learning_commons_evaluators import EvaluatorError, RateLimitError

for attempt in range(3):
  try:
    result = evaluator.evaluate_sync(input)
    break
  except EvaluatorError as e:
    # Every EvaluatorError exposes a boolean retryable attribute
    if not e.retryable or attempt == 2:
      raise
    delay = e.retry_after if isinstance(e, RateLimitError) and e.retry_after else 2 ** attempt # retry_after is in seconds
    time.sleep(delay)
```

## `EvaluatorError`

Evaluators can throw 3 types of `EvaluatorError`s:

| Type                   | Description                                         |
| ---------------------- | --------------------------------------------------- |
| `ConfigurationError`   | Missing or invalid API keys                         |
| `InputValidationError` | Invalid input (text too short, invalid grade, etc.) |
| `APIError`             | Other API errors ([Subtypes](#apierror))            |

## `APIError`

`APIError`s can be broken down further into more specific error types:

| Type                    | Description                                                |
| ----------------------- | ---------------------------------------------------------- |
| `AuthenticationError`   | Invalid API keys                                           |
| `RateLimitError`        | Rate limit exceeded; wait and retry                        |
| `NetworkError`          | Network connectivity issues                                |
| `RequestTimeoutError`   | Request timed out                                          |
| `OutputValidationError` | Output failed to parse or didn't match the expected schema |

## Retries

Every `EvaluatorError` exposes a boolean `retryable` attribute:

| Retryable by default              | Not retryable by default          |
| --------------------------------- | --------------------------------- |
| `RateLimitError`                  | `ConfigurationError`              |
| `NetworkError`                    | `InputValidationError`            |
| `RequestTimeoutError`             | `AuthenticationError`             |
| `OutputValidationError`           | `APIError` with a 4xx status code |
| `APIError` with a 5xx status code |                                   |

<Note>
  To flag a specific instance (e.g., a permanently-bad hostname), `APIError`s and `NetworkError`s also accept `retryable` as an **init** kwarg. `APIError`s with status code >= 500 and an unspecified `retryable` attribute will default to `retryable: True`.
</Note>
