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

# Policy Rule • Rust AI Agent SDK

> PolicyRule: A policy rule.

# PolicyRule

> Defined in the [**policy**](../modules/policy) module.

<Badge color="orange">Rust AI Agent SDK</Badge>

A policy rule.

## Fields

| Name          | Type                   | Description                       |
| ------------- | ---------------------- | --------------------------------- |
| `name`        | `String`               | Rule name                         |
| `description` | `Option&lt;String&gt;` | Rule description                  |
| `pattern`     | `Option&lt;String&gt;` | Pattern to match (regex)          |
| `keywords`    | `Vec&lt;String&gt;`    | Keywords to match                 |
| `action`      | `PolicyAction`         | Action to take                    |
| `enabled`     | `bool`                 | Whether the rule is enabled       |
| `priority`    | `i32`                  | Priority (higher = checked first) |
| `replacement` | `Option&lt;String&gt;` | Replacement text for redaction    |

## Methods

### `new`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn new(name: impl Into<String>) -> Self
```

Create a new rule.

**Parameters:**

| Name   | Type                      |
| ------ | ------------------------- |
| `name` | `impl Into&lt;String&gt;` |

### `description`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn description(mut self, desc: impl Into<String>) -> Self
```

Set description.

**Parameters:**

| Name   | Type                      |
| ------ | ------------------------- |
| `desc` | `impl Into&lt;String&gt;` |

### `pattern`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn pattern(mut self, pattern: impl Into<String>) -> Self
```

Set pattern.

**Parameters:**

| Name      | Type                      |
| --------- | ------------------------- |
| `pattern` | `impl Into&lt;String&gt;` |

### `keyword`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn keyword(mut self, keyword: impl Into<String>) -> Self
```

Add keyword.

**Parameters:**

| Name      | Type                      |
| --------- | ------------------------- |
| `keyword` | `impl Into&lt;String&gt;` |

### `action`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn action(mut self, action: PolicyAction) -> Self
```

Set action.

**Parameters:**

| Name     | Type           |
| -------- | -------------- |
| `action` | `PolicyAction` |

### `priority`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn priority(mut self, priority: i32) -> Self
```

Set priority.

**Parameters:**

| Name       | Type  |
| ---------- | ----- |
| `priority` | `i32` |

### `replacement`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn replacement(mut self, replacement: impl Into<String>) -> Self
```

Set replacement.

**Parameters:**

| Name          | Type                      |
| ------------- | ------------------------- |
| `replacement` | `impl Into&lt;String&gt;` |

### `enable`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn enable(&mut self) -> ()
```

Enable the rule.

### `disable`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn disable(&mut self) -> ()
```

Disable the rule.

### `matches`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn matches(&self, content: &str) -> bool
```

Check if content matches this rule.

**Parameters:**

| Name      | Type   |
| --------- | ------ |
| `content` | `&str` |

### `apply`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn apply(&self, content: &str) -> PolicyResult
```

Apply the rule to content.

**Parameters:**

| Name      | Type   |
| --------- | ------ |
| `content` | `&str` |

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-rust/praisonai/src/policy/mod.rs#L118">
  `praisonai/src/policy/mod.rs` at line 118
</Card>

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="Rust Policy" icon="file-shield" href="/docs/rust/policy" />

  <Card title="Rust Security" icon="lock" href="/docs/rust/security" />
</CardGroup>
