> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/guardrails/llms.txt.
> For full documentation content, see https://docs.nvidia.com/nemo/guardrails/llms-full.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/guardrails/_mcp/server.

# nemoguardrails.library.clavata.utils

## Module Contents

### Classes

| Name                                                                                   | Description                                                      |
| -------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
| [`AttemptsExceededError`](#nemoguardrails-library-clavata-utils-AttemptsExceededError) | Exception raised when the maximum number of retries is exceeded. |

### Functions

| Name                                                                               | Description                                                                        |
| ---------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| [`calculate_exp_delay`](#nemoguardrails-library-clavata-utils-calculate_exp_delay) | Handles calculation of the delay for a specific attempt. Note that we specifically |
| [`exponential_backoff`](#nemoguardrails-library-clavata-utils-exponential_backoff) | Exponential backoff retry mechanism.                                               |

### Data

[`P`](#nemoguardrails-library-clavata-utils-P)

[`ReturnT`](#nemoguardrails-library-clavata-utils-ReturnT)

### API

```python
class nemoguardrails.library.clavata.utils.AttemptsExceededError(
    attempts: int,
    max_attempts: int,
    last_exception: typing.Optional[Exception]
)
```

Exception

**Bases:** `Exception`

Exception raised when the maximum number of retries is exceeded.

```python
nemoguardrails.library.clavata.utils.calculate_exp_delay(
    retries: int,
    initial_delay: float,
    max_delay: float,
    jitter: bool
) -> float
```

Handles calculation of the delay for a specific attempt. Note that we specifically
ask for the number of retries, not the number of attempts, because the first attempt
is the initial call and we want the first delay to be raised to the power of 0.

Using "retries" instead of "attempts" makes it clearer what the input is, even
though a value called "attempts" is being passed in below.

Because this is an exponential backoff, the factor of increase is always 2.

**Parameters:**

The number of retries made so far.

The initial delay.

The maximum delay.

Whether to apply jitter to the delay. We use a full-jitter approach.

```python
nemoguardrails.library.clavata.utils.exponential_backoff(
    max_attempts: int = 3,
    initial_delay: float = 1.0,
    max_delay: float = 10.0,
    jitter: bool = True,
    retry_exceptions: typing.Union[type[Exception], collections.abc.Iterable[type[Exception]]] = Exception,
    on_permanent_failure: typing.Optional[collections.abc.Callable[[int, Exception], collections.abc.Awaitable[typing.Any]]] = None
)
```

Exponential backoff retry mechanism.

```python
nemoguardrails.library.clavata.utils.P = ParamSpec('P')
```

```python
nemoguardrails.library.clavata.utils.ReturnT = TypeVar('ReturnT')
```