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

# Guardrails for Decisions Requests

> Apply guardrails to the caller-supplied state field on /v1/decisions requests, without scanning your own prompt instructions.

The Prisma AIRS AI Gateway's guardrails also cover `/v1/decisions`, the typed-judgment endpoint. This lets you screen the content a decision is made about before it reaches the model, the same way you would for a chat or embedding request. Guardrails work with both [request shapes](https://docs.portkey.ai/docs/aigw/product/ai-gateway/decisions-api.md#request-shapes) and every [supported provider](https://docs.portkey.ai/docs/aigw/product/ai-gateway/decisions-api.md#supported-providers).

## Why Use Guardrails for Decisions?

A decisions request has three parts: `model`, `questions`, and the content to judge. The content is `state` in the Jev shape and `input` in the OpenAI shape. Only that content is caller-supplied — `model` and `questions` (including any `criteria`, `choices`, or `levels`) are your own application's instructions. Guardrails scan the content alone, so they check what a user or upstream system fed into the judgment, never your prompt design.

This matters because the content often carries the same kind of untrusted text you'd otherwise send to a chat model — support tickets, form submissions, extracted document text — before it's judged, scored, or classified. Guardrails let you catch PII, prompt injection, or policy violations in that content before the judgment call is made.

## How It Works

Guardrails for decisions run only at the **before-request** stage, on the content to judge only:

```mermaid theme={"system"}
flowchart LR
    App[Your Application] --> Portkey[AI Gateway]
    Portkey --> Guardrails[Guardrail Checks on state / input]

    Guardrails -->|Pass| LLM[Decisions Provider]
    Guardrails -->|Fail + deny=false| LLM
    Guardrails -->|Fail + deny=true, softDeny200=true| SoftDeny[/Soft Deny\nStatus: 200/]
    Guardrails -->|Fail + deny=true| Blocked[/Blocked\nStatus: 446/]

    LLM --> Success[Typed answers]

    class Success success
    class SoftDeny warning
    class Blocked danger
```

1. Your application sends the content to judge, `model`, and `questions` to `/v1/decisions`.
2. The AI Gateway's before-request guardrails scan the content — `state` in the Jev shape, or the text in `input` in the OpenAI shape. They never scan `model`, `questions`, or nested `criteria`, `choices`, or `levels`.
3. If all checks pass, the request (with the content possibly redacted by a mutator) is forwarded to the provider.
4. If a check fails, the configured [guardrail action](https://docs.portkey.ai/docs/aigw/product/guardrails.md) applies: log only, soft-deny with a `200`, or hard-deny with a `446`.

> [!NOTE]
>
> There are no after-request (output) guardrails on `/v1/decisions`. A successful answer is a typed judgment — a choice, a score, or a probability — with no free text to scan, so only `input_guardrails` apply. This mirrors [Guardrails for Embeddings](https://docs.portkey.ai/docs/aigw/product/guardrails/embedding-guardrails.md).

## Redacting the Content

Mutator guardrails (for example, PII redaction) can rewrite the content before it's forwarded. Redaction is written back into the shape the request used.

**Jev shape (`state`)**

* If `state` was a plain string, the redacted text replaces it directly.
* If `state` was a JSON object or array, the redacted text is parsed back into JSON before being written back.
* If a mutator's output is no longer valid JSON for an object/array `state`, the AI Gateway keeps the original `state` unchanged rather than forwarding corrupted content.

**OpenAI shape (`input`)**

* If `input` was a string, the redacted text replaces it.
* If `input` was a list of messages, each message's text is redacted in place. Message `role` and non-text parts such as `input_image` are left unchanged. Only message text and `input_text` parts are scanned.

## Response When a Guardrail Fails

A hard deny (`deny: true`, no soft-deny) returns `446` with the standard guardrail error shape:

```json theme={"system"}
{
  "error": {
    "message": "The guardrail checks defined in the config failed. You can find more information in the `hook_results` object.",
    "type": "hooks_failed",
    "param": null,
    "code": null
  },
  "hook_results": {
    "before_request_hooks": [ /* per-check verdicts */ ],
    "after_request_hooks": []
  }
}
```

A soft deny (`deny: true`, `softDeny200: true`) returns `200` with empty `answers` instead of an OpenAI-style error envelope, keeping the response shape consistent with a normal decisions response. `answers` is `{}` for a Jev-shaped request and `[]` for an OpenAI-shaped request:

```json theme={"system"}
{
  "answers": {},
  "message": "The guardrail checks defined in the config failed. You can find more information in the `hook_results` object.",
  "hook_results": {
    "before_request_hooks": [ /* per-check verdicts */ ],
    "after_request_hooks": []
  }
}
```

## Setting Up Guardrails for Decisions

### 1. Create a Guardrail

* Navigate to the `Guardrails` page and click `Create`.
* Select a check that supports `beforeRequestHook` (for example, PII Detection, Regex Match, Moderate Content).
* Configure the check parameters and set the action for failed checks (log, soft-deny, or hard-deny).
* Save the guardrail to get its ID.

> [!NOTE]
>
> Only guardrails that support `beforeRequestHook` run on `/v1/decisions`. Guardrails scoped to `afterRequestHook` only are skipped for this endpoint.

### 2. Add the Guardrail to Your Config

```json theme={"system"}
{
  "input_guardrails": ["gr-xxx", "gr-yyy"]
}
```

### 3. Use the Config with a Decisions Request

```bash cURL theme={"system"}
curl https://aigw.portkey.ai/v1/decisions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $PORTKEY_API_KEY" \
  -H "x-portkey-config: pc-xxx" \
  -d '{
    "model": "@your-typesafe-slug/jev-latest",
    "state": "Help! My payouts have been failing for 3 days.",
    "questions": {
      "department": {
        "type": "choice",
        "instructions": "Which team should handle this?",
        "criteria": { "billing": "Payments", "technical": "Bugs" }
      }
    }
  }'
```

## Learn More

> [card] [Guardrails Overview](https://docs.portkey.ai/docs/aigw/product/guardrails.md)
>
> Create guardrails, configure actions, attach to requests

> [card] [Supported Endpoints & Capabilities](https://docs.portkey.ai/docs/aigw/product/guardrails/capabilities.md)
>
> Where guardrails run across the gateway

> [card] [Decisions API](https://docs.portkey.ai/docs/aigw/product/ai-gateway/decisions-api.md)
>
> Request shapes, supported providers, and question types

> [card] [TypeSafe (Jev)](https://docs.portkey.ai/docs/aigw/integrations/llms/typesafe.md)
>
> Provider setup and quick start for /v1/decisions

> [card] [List of Guardrail Checks](https://docs.portkey.ai/docs/aigw/product/guardrails/list-of-guardrail-checks.md)
>
> All built-in and partner checks


## Related topics

- [Request Parameters Check](https://docs.portkey.ai/docs/aigw/integrations/guardrails/request-parameters-check.md)
- [Guardrails for Embedding Requests](https://docs.portkey.ai/docs/aigw/product/guardrails/embedding-guardrails.md)
- [F5 Guardrails](https://docs.portkey.ai/docs/aigw/integrations/guardrails/f5-guardrails.md)
- [Azure Guardrails](https://docs.portkey.ai/docs/aigw/integrations/guardrails/azure-guardrails.md)
- [AWS Bedrock Guardrails](https://docs.portkey.ai/docs/aigw/integrations/guardrails/bedrock-guardrails.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.