# Update rule

Update an existing rule. Version number increments automatically.

#### Path Parameters

**`org_id`** string required

Organization ID (org_ prefixed string) where the rule belongs.

**`rule_id`** string required

Rule ID with `rule_` prefix.

#### Request Body

All fields are optional. Only provided fields will be updated.

**`name`** string optional

Updated name for the rule.

**`description`** string optional

Updated description.

**`content`** string optional

Updated rule content. Recommended to keep below 10,000 characters for optimal performance.

**`category`** string optional

Updated category.

**`rule_type`** string optional

Updated rule type.

**`is_active`** boolean optional

Updated active status.

**`scope`** string optional

Updated scope.

**`apply_mode`** string optional

Updated apply mode.

**`is_public`** boolean optional

Updated public visibility status.

## Returns

Returns the updated [Rule object](/docs/api-reference/objects/rule-object) with incremented version number.

## Access Control

Requires `edit` or `owner` access to the rule.

## Version Control

Version number increments automatically on each update. Previous versions are not stored.

Update Content

```bash
curl -X PUT https://api.aitronos.com/v1/organizations/org_abc123def456/rules/rule_abc123 \
  -H "X-API-Key: $FREDDY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "Updated rule content with new guidelines."
  }'
```


```python Python SDK
from aitronos import Aitronos

client = Aitronos(api_key="your-api-key")

rule = client.rule_operations.update_rule(
    "org_abc123",
    "rule_abc123",
    content="Updated rule content with new guidelines.",
)
print(f"Updated to version {rule.version}")
```


```python
import requests
import os

api_key = os.environ["FREDDY_API_KEY"]

response = requests.put(
    "https://api.aitronos.com/v1/organizations/org_abc123def456/rules/rule_abc123",
    headers={
        "X-API-Key": api_key,
        "Content-Type": "application/json"
    },
    json={
        "content": "Updated rule content with new guidelines."
    }
)

rule = response.json()
print(f"Updated to version {rule['data']['version']}")
```


```javascript
const response = await fetch('https://api.aitronos.com/v1/organizations/org_abc123def456/rules/rule_abc123', {
  method: 'PUT',
  headers: {
    'X-API-Key': process.env.FREDDY_API_KEY,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    content: 'Updated rule content with new guidelines.'
  })
});

const rule = await response.json();
console.log(`Updated to version ${rule.data.version}`);
```

Update Multiple Fields

```bash
curl -X PUT https://api.aitronos.com/v1/organizations/org_abc123def456/rules/rule_abc123 \
  -H "X-API-Key: $FREDDY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Updated Customer Support Guidelines",
    "description": "Updated description",
    "category": "communication",
    "is_active": true,
    "metadata": {
      "version": "2.0",
      "updated_by": "admin"
    }
  }'
```


```python Python SDK
from aitronos import Aitronos

client = Aitronos(api_key="your-api-key")

rule = client.rule_operations.update_rule(
    "org_abc123",
    "rule_abc123",
    name="Updated Customer Support Guidelines",
    description="Updated description",
    is_active=True,
)
print(rule.version)
```


```python
import requests
import os

api_key = os.environ["FREDDY_API_KEY"]

response = requests.put(
    "https://api.aitronos.com/v1/organizations/org_abc123def456/rules/rule_abc123",
    headers={
        "X-API-Key": api_key,
        "Content-Type": "application/json"
    },
    json={
        "name": "Updated Customer Support Guidelines",
        "description": "Updated description",
        "category": "communication",
        "is_active": True,
        "metadata": {
            "version": "2.0",
            "updated_by": "admin"
        }
    }
)

rule = response.json()
```


```javascript
const response = await fetch('https://api.aitronos.com/v1/organizations/org_abc123def456/rules/rule_abc123', {
  method: 'PUT',
  headers: {
    'X-API-Key': process.env.FREDDY_API_KEY,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    name: 'Updated Customer Support Guidelines',
    description: 'Updated description',
    category: 'communication',
    is_active: true,
    metadata: {
      version: '2.0',
      updated_by: 'admin'
    }
  })
});

const rule = await response.json();
```

**Response:**

200 OK

```json
{
  "success": true,
  "data": {
    "id": "rule_abc123",
    "name": "Updated Customer Support Guidelines",
    "description": "Updated description",
    "content": "Always be polite and professional...",
    "content_preview": "Always be polite and professional...",
    "category": "communication",
    "rule_type": "guideline",
    "scope": "organization",
    "organization_id": "org_xyz789",
    "created_by": "usr_456",
    "is_public": false,
    "is_active": true,
    "version": 2,
    "metadata": {
      "version": "2.0",
      "updated_by": "admin"
    },
    "created_at": "2025-11-23T10:00:00Z",
    "updated_at": "2025-11-23T11:00:00Z"
  }
}
```

403 Forbidden

```json
{
  "success": false,
  "error": {
    "code": "ACCESS_DENIED",
    "message": "You need edit or owner access to update this rule.",
    "system_message": "You need edit or owner access to update this rule.",
    "type": "authorization_error",
    "status": 403,
    "details": {},
    "trace_id": "req_abc123xyz",
    "timestamp": "2025-12-22T15:30:00Z"
  }
}
```

404 Not Found

```json
{
  "success": false,
  "error": {
    "code": "RULE_NOT_FOUND",
    "message": "We couldn't find that rule.",
    "system_message": "We couldn't find that rule.",
    "type": "client_error",
    "status": 404,
    "details": {},
    "trace_id": "req_abc123xyz",
    "timestamp": "2025-12-22T15:30:00Z"
  }
}
```

## Related Resources

- [Create Rule](/docs/api-reference/rules/create)
- [List Rules](/docs/api-reference/rules/list)