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

# Policies

> Named sets of guardrails that build on a base policy, and apply to every request, to some models, or to the requests that name them.

A policy is a named set of [guardrails](https://developers.telnyx.com/docs/agent-gateway/authorization/guardrails.md). A policy can build on a base policy, and add guardrails to it or remove some. Attachments say where each policy applies.

[`POST /v2/agent_gateways/{id}/policies`](https://developers.telnyx.com/api-reference/agent-gateway-policies/create-a-policy) creates one. This policy runs the guardrails of `baseline` and a custom code check, on requests for `GLM-5.3-Flash`:

```json theme={null}
{
  "name": "strict",
  "base": "baseline",
  "guardrails": { "add": ["no-forbidden"] },
  "model": "GLM-5.3-Flash"
}
```

## Inheritance

A policy that builds on a base policy starts with the base's guardrails, then adds and removes its own. A `strict` policy can build on a `baseline` policy that masks personal data, and add a custom code check, so both run.

## Conditions

A policy can apply only to some models, named exactly or by a regular expression. Its guardrails then run only on requests for those models.

## Attachments

[`POST /v2/agent_gateways/{id}/policy_attachments`](https://developers.telnyx.com/api-reference/agent-gateway-policy-attachments/attach-a-policy) applies a policy to every request, or to requests for the models it names. A model name in an attachment can use `*` as a wildcard:

```json theme={null}
{
  "policy": "strict",
  "models": ["GLM-5.3*"],
  "priority": 10
}
```

An attachment with a priority applies before the others. A default attachment, with `"default": true`, applies only to the requests that no other attachment matches.

A request can also add policies by name, in `policies`:

```json theme={null}
{
  "model": "GLM-5.3-Flash",
  "messages": [{ "role": "user", "content": "Summarize this support ticket." }],
  "policies": ["strict"]
}
```

Like a guardrail, a policy only adds checks. It cannot turn off a guardrail that runs on every request.

## Pipelines

A policy can run its guardrails as ordered steps instead. Each step says what happens when its guardrail passes, fails, or errors:

* `next` goes on to the next step.
* `allow` allows the request.
* `block` blocks the request.
* `respond` replaces the response with the step's `message`.

```json theme={null}
{
  "name": "piped",
  "pipeline": {
    "hook": "before_request",
    "steps": [
      { "guardrail": "mask-pii", "on_pass": "next", "on_fail": "block" },
      { "guardrail": "no-forbidden", "on_fail": "respond", "message": "Not allowed." }
    ]
  }
}
```

A policy that is named by an attachment, or that another policy builds on, cannot be deleted.
