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

# Rules and Controls

> Understand Pylva rules for budgets, routing, throttles, failover, and recommendations.

Rules help teams react to spend and reliability conditions without redeploying agent code.

## Rule types

| Rule                 | When it runs          | What it does                                                 |
| -------------------- | --------------------- | ------------------------------------------------------------ |
| Cost threshold       | Post-call             | Sends an alert when spend crosses a threshold.               |
| Budget limit         | Pre-call or post-call | Warns or blocks when a customer or pool exceeds a budget.    |
| Customer throttle    | Pre-call              | Blocks traffic for a selected customer.                      |
| Model routing        | Pre-call              | Rewrites matching calls to another provider or model.        |
| Reliability failover | Pre-call              | Uses a backup path when the primary model path is unhealthy. |
| Margin protection    | Scheduled analysis    | Finds margin drift and recommends action.                    |

## Draft before active

Rules should be reviewed before they affect production traffic. Pylva supports draft rules so teams can preview impact before activation.

## Conflict resolution

When more than one rule matches a call, the most specific rule wins:

1. Customer-specific rules beat pooled rules.
2. Step-specific rules beat general rules.
3. If specificity is tied, the most recently updated rule wins.

## Fail-open principle

Pylva should not become the reason your agent is unavailable. SDK-side controls pass through when the rules cache is cold, pricing is unknown, or Pylva is unreachable. The exception is an active hard-stop rule that the SDK has already cached and can enforce locally.

## Operational advice

* Start with alert-only rules.
* Add budget hard stops to customer plans that need hard cost ceilings.
* Use model routing on narrow steps before broad rollouts.
* Keep failover rules explicit and tested before activating them.
