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

# Policies

> A policy is a configured governance rule on a gateway's traffic — rate limits, budgets, caching, tool governance, guardrails, and more — run at request/response stages, scoped globally or per consumer.

A **policy** attaches behavior to a gateway's traffic. Each policy configures one built-in
plugin — identified by its **`slug`** (e.g. `rate_limiter`, `semantic_cache`, `trustguard`) — with
`settings`, and runs at one or more lifecycle **stages**, with a `mode`, `priority`, and a
scope (global or per consumer).

<Note>
  A policy's `slug` is the **plugin name** it configures — always the underscore form
  (`rate_limiter`, `token_rate_limiter`, `request_size_limiter`, `semantic_cache`, …). Browse
  the live catalog and its settings schema at `GET /v1/policies-catalog` (same grouping as the
  Admin Console policy picker).
</Note>

## Built-in policies

TrustGate ships **13 policies** in the Admin Console catalog, grouped as below:

### Traffic control

| Policy (`slug`)                                                | Purpose                                                            |
| -------------------------------------------------------------- | ------------------------------------------------------------------ |
| [`rate_limiter`](/trustgate/policies/rate-limiting)            | Per-consumer / per-gateway request rate limiting (sliding window). |
| [`request_size_limiter`](/trustgate/policies/request-size)     | Reject requests above a byte / character budget.                   |
| [`per_tool_rate_limiter`](/trustgate/policies/tool-governance) | Rate-limit individual tool calls observed in responses.            |

### Quota

| Policy (`slug`)                                                          | Purpose                                                            |
| ------------------------------------------------------------------------ | ------------------------------------------------------------------ |
| [`token_rate_limiter`](/trustgate/policies/rate-limiting) ("LLM Budget") | Token or dollar budgets over time windows, aggregate or per-model. |

### Routing

| Policy (`slug`)                                        | Purpose                                         |
| ------------------------------------------------------ | ----------------------------------------------- |
| [`semantic_cache`](/trustgate/policies/semantic-cache) | Exact or embedding-similarity response caching. |

### Prompt management

| Policy (`slug`)                                                | Purpose                                                                    |
| -------------------------------------------------------------- | -------------------------------------------------------------------------- |
| [`prompt_template`](/trustgate/policies/prompt-model-controls) | Inject context-bound system prompts and render named, versioned templates. |

### Tool governance

| Policy (`slug`)                                         | Purpose                                                           |
| ------------------------------------------------------- | ----------------------------------------------------------------- |
| [`tool_injection`](/trustgate/policies/tool-governance) | Inject operator-authored tools into the request before the model. |

### Guardrails

| Policy (`slug`)                                          | Purpose                                                                                                    |
| -------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| [`trustguard`](/trustgate/policies/guardrails)           | Inspect prompts/responses with [TrustGuard](/trustguard/overview) (jailbreaks, PII, toxicity, tool abuse). |
| [`openai_moderation`](/trustgate/policies/guardrails)    | Screen text with the OpenAI Moderations API.                                                               |
| [`azure_content_safety`](/trustgate/policies/guardrails) | Screen text with Azure AI Content Safety.                                                                  |
| [`bedrock_guardrail`](/trustgate/policies/guardrails)    | Apply an AWS Bedrock guardrail (topics, content, PII, grounding).                                          |
| [`regex_replace`](/trustgate/policies/guardrails)        | Rewrite request or response text with ordered RE2 regular expressions.                                     |

> **NeuralTrust-native detection.** The gateway ships several guardrail plugins, but the
> deepest jailbreak / PII / toxicity / tool-abuse detection is [TrustGuard](/trustguard/overview),
> attached via the [`trustguard`](/trustgate/policies/guardrails) policy. See the
> [TrustGate integration](/trustguard/integrations/gateway).

To restrict which models a consumer may call, use consumer
[`model_policies`](/trustgate/routing/model-resolution) rather than a catalog policy.

## Stages

A policy fires in one or more lifecycle **stages**:

| Stage           | When                                                                  |
| --------------- | --------------------------------------------------------------------- |
| `pre_request`   | Before the request is forwarded upstream.                             |
| `pre_response`  | After the upstream responds, before returning to the client.          |
| `post_response` | After the response is returned (e.g. cache populate, budget accrual). |

Some policies span two stages — the [semantic cache](/trustgate/policies/semantic-cache)
looks up at `pre_request` and populates at `post_response`; the
[LLM Budget](/trustgate/policies/rate-limiting) checks at `pre_request` and accrues usage at
`post_response`. (A `post_request` stage exists in the model but is not executed on the proxy
forward path.)

## Mode

A policy's `mode` sets its enforcement intent. Not every plugin supports every mode:

| Mode       | Behavior                                                         |
| ---------- | ---------------------------------------------------------------- |
| `enforce`  | Act on violations — reject, transform, or block (default).       |
| `throttle` | Delay rather than reject (supported by the rate/budget plugins). |
| `observe`  | Record only — no enforcement.                                    |

## Ordering and scope

| Field      | Meaning                                                    |
| ---------- | ---------------------------------------------------------- |
| `slug`     | The built-in plugin this policy configures.                |
| `settings` | The policy's configuration (limits, thresholds, origins…). |
| `priority` | Lower runs earlier.                                        |
| `parallel` | Run alongside other same-priority policies concurrently.   |
| `global`   | Apply to **all** consumers in the gateway.                 |
| `enabled`  | Toggle without deleting.                                   |

Global policies are the gateway-wide baseline (e.g. a default request-size guard);
consumer-scoped policies tune behavior per tenant. The proxy resolves both sets and runs
them in `priority` order. When same-priority policies run in `parallel`, only one may mutate
a given part of the request/response per batch. Policies that partition by a key (the rate
limiters and budgets) also accept a `group_by_header` to sub-partition within scope.

## Managing policies

CRUD lives under `/v1/gateways/{gateway_id}/policies`, plus:

* `…/{id}/global` (`POST`/`DELETE`) — promote/demote to global.
* `…/{id}/duplicate` (`POST`) — clone a policy.
* Attach to a consumer via `…/consumers/{id}/policies/{policy_id}`.

See the [Policies API](/trustgate/api/overview).
