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

# Rules

> Documentation for Rules

### Rules

Rules are evaluated in order. The first matching rule that sets a `pin_tier` wins for that action. Deny rules are cumulative — multiple rules can deny multiple tiers.

#### deny\_tiers

Excludes tiers when the condition is true.

```python theme={null}
# never route to small models when the conversation is long
Rule(if_context_tokens_gt=4000, deny_tiers=["small"])

# never route to small or medium when cost is a concern
Rule(if_estimated_cost_gt=0.05, deny_tiers=["small", "medium"])
```

#### pin\_tier

Forces a specific tier regardless of other rules. First pin wins.

```python theme={null}
# always use the best model for sensitive tasks
Rule(if_task="legal-review", pin_tier="large")
Rule(if_task="medical-advice", pin_tier="large")
```

#### prefer\_tier

Softly prefers a tier. Overridden by deny rules.

```python theme={null}
# prefer cheap models when cost is low
Rule(prefer_tier="small", if_estimated_cost_gt=0.001)
```

#### escalate on error

Auto-retry on the next tier when a specific error code is received.

```python theme={null}
Rule(if_error_code=429, escalate=True)   # rate limit → try next tier
Rule(if_error_code=529, escalate=True)   # overloaded → try next tier
```

#### Rule conditions reference

| Condition              | Type   | Description                                        |
| ---------------------- | ------ | -------------------------------------------------- |
| `if_context_tokens_gt` | int    | Fires when estimated token count exceeds this      |
| `if_task`              | string | Fires when `task_hint` matches exactly             |
| `if_error_code`        | int    | Fires when previous call returned this HTTP status |
| `if_estimated_cost_gt` | float  | Fires when estimated cost (USD) exceeds this       |

All conditions on a single `Rule` are AND-ed. Use separate rules for OR logic.

***
