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

# Attach a guardrail rule

> The rule

### Path parameters

<ParamField path="id" type="string (uuid)" required>
  The agent id.
</ParamField>

### Request body

`CreateRule`

<ParamField body="rule_name" type="string" required />

<ParamField body="rule_type" type="string" required>
  One of: escalation, qualification, response, routing.
</ParamField>

<ParamField body="description" type="string" />

<ParamField body="activated" type="boolean" />

<ParamField body="conditions" type="object">
  \{any|all: \[\{field, operator, value}]}. Fields: company\_size, confidence, intent, knowledge\_sources, latest\_message, missing\_required\_fields, timeline. Operators: contains\_any, eq, exists, gte, in, lt, not\_empty.
</ParamField>

<ParamField body="actions" type="any[]">
  \[\{type, ...}]. Types: collect\_fields, fallback, handoff, include\_sources, require\_context, require\_source\_for\_claims, require\_verification, response\_pattern, tag.
</ParamField>

### Response

`Rule`

<ResponseField name="object" type="string" />

<ResponseField name="id" type="string" />

<ResponseField name="name" type="string,null" />

<ResponseField name="type" type="string,null" />

<ResponseField name="description" type="string,null" />

<ResponseField name="activated" type="boolean" />

<ResponseField name="conditions" type="any" />

<ResponseField name="actions" type="any" />

<ResponseField name="agent_id" type="string,null" />

### Status codes

| Code  | Meaning                                                                                                                                                                                                                                        |
| ----- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `201` | The rule                                                                                                                                                                                                                                       |
| `400` | Invalid request. `issues` names the offending field(s).                                                                                                                                                                                        |
| `401` | Missing, invalid, or expired API key.                                                                                                                                                                                                          |
| `403` | The key lacks a required scope.                                                                                                                                                                                                                |
| `404` | Not found, or not in the organization that owns the key.                                                                                                                                                                                       |
| `409` | Conflict — either the creation ceiling was reached for this organization (`agent_limit_reached`), or a request with the same Idempotency-Key is still in flight (`idempotency_in_progress`); retry the latter after the first attempt settles. |
| `422` | The Idempotency-Key was already used with a DIFFERENT request body (`idempotency_key_reused`). Reuse a key only to retry the identical request.                                                                                                |
| `429` | Rate limit exceeded.                                                                                                                                                                                                                           |

### Access

|                |                        |
| -------------- | ---------------------- |
| Required scope | `agents:write`         |
| Rate limit     | 30 requests per minute |

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url 'https://response.stateset.com/api/v1/agents/{id}/rules' \
    --header 'Authorization: Bearer YOUR_API_KEY' \
    --header 'Content-Type: application/json' \
    --data '{
    "rule_name": "string",
    "rule_type": "string",
    "description": "string",
    "activated": true,
    "conditions": {
      "any": [],
      "all": []
    },
    "actions": []
  }'
  ```
</RequestExample>

<ResponseExample>
  ```json 201 theme={null}
  {
    "object": "string",
    "id": "string",
    "name": null,
    "type": null,
    "description": null,
    "activated": true,
    "conditions": null,
    "actions": null,
    "agent_id": null
  }
  ```
</ResponseExample>
