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

# Resilience

> Error propagation, retry/backoff, cost-based rate limiters, SSRF guards on URL-fetching tools.

Resilience examples enact production patterns for keeping an LLM app up. Sources under [`examples/resilience/`](https://github.com/0xvasanth/cognis/tree/main/examples/resilience).

| Name                         | Scenario                                                                                                                           | Source                                                                                             |
| ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
| `resilience_error_handling`  | User submits an age string; show how parse errors propagate through a Runnable chain so the caller can surface a friendly message. | [src](https://github.com/0xvasanth/cognis/blob/main/examples/resilience/error_handling.rs)         |
| `resilience_error_recovery`  | URL shortener that fails twice then succeeds — exponential backoff retry keeps the user-facing call working.                       | [src](https://github.com/0xvasanth/cognis/blob/main/examples/resilience/error_recovery.rs)         |
| `resilience_rate_limiters`   | Cost-based budget — cap LLM spend at \$1/min using TokenBucket / SlidingWindow / CostBased / Composite.                            | [src](https://github.com/0xvasanth/cognis/blob/main/examples/resilience/advanced_rate_limiters.rs) |
| `resilience_ssrf_protection` | URL-fetch tool that gets a URL from user input — reject internal IPs, localhost, and AWS metadata before any HTTP call.            | [src](https://github.com/0xvasanth/cognis/blob/main/examples/resilience/ssrf_protection.rs)        |

## How to run

```bash theme={null}
cargo run -p cognis-examples --example resilience_ssrf_protection
cargo run -p cognis-examples --example resilience_rate_limiters
```

## See also

<CardGroup cols={2}>
  <Card title="Resilience guide" icon="shield" href="/production/resilience">
    Wrappers, middleware, recovery patterns.
  </Card>

  <Card title="Caching" icon="bolt" href="/production/caching">
    Don't pay twice.
  </Card>

  <Card title="Security" icon="lock" href="/production/security">
    PII, deny-lists, sandboxing.
  </Card>
</CardGroup>
