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

# Wingback

> Point TrueFoundry Custom Guardrails at Wingback to detect and block or mask PII, secrets and prompt injection on LLM input and output, with no wrapper service.

Point [Custom Guardrails](https://www.truefoundry.com/docs/ai-gateway/custom-guardrails.md) directly at [Wingback](https://wingback.ai). No adapter or wrapper service is required: Wingback's TrueFoundry endpoints accept the custom-guardrail request as the gateway sends it, and return TrueFoundry's response format for both Validate (allow or block) and Mutate (mask).

## What is Wingback?

Wingback secures AI agents and models at runtime. In the Wingback console you define protection groups and policies, such as PII/PHI detection, secrets detection, prompt injection defense and custom entity rules, and set each integration to **Monitor** (log only) or **Enforce** (block or mask).

TrueFoundry calls Wingback on the `llm_input` and `llm_output` hooks and applies the returned verdict. Wingback records each finding under **Security Center → External Gateway**, attributed to your TrueFoundry integration.

## How the integration works

You create two Custom Guardrail configs, one per hook, each with its own URL:

* **Input:** `https://api.wingback.ai/connectors/integrations/truefoundry/v1/guardrail/input`
* **Output:** `https://api.wingback.ai/connectors/integrations/truefoundry/v1/guardrail/output`

Your Wingback integration API key goes in **Auth Data** as a Bearer token. Use the same key on both configs.

1. TrueFoundry POSTs its standard custom-guardrail body: `requestBody` on input, and `requestBody` plus `responseBody` on output.
2. Wingback evaluates the content against the protection group and mode bound to the integration key. The key decides the tenant, the mode and the protection group.
3. Wingback returns HTTP 200 with a verdict and, for Mask, the masked body.

### Response contract

| HTTP | Body | Meaning |
| - | - | - |
| `200` | `{"verdict": true, "message": null}` | Allow. TrueFoundry shows the check as passed. In Monitor mode Wingback returns this for every request, including requests with findings. |
| `200` | `{"verdict": false, "message": "..."}` | Block. The client receives HTTP 400 with `error.type: guardrail_checks_failed`. |
| `200` | `{"verdict": true, "transformed": true, "result": {...}}` | Mask. When the guardrail's Operation is **Mutate**, TrueFoundry replaces `requestBody` (input) or `responseBody` (output) with `result`. Under **Validate**, TrueFoundry ignores it. |

Wingback returns policy blocks as 2xx with `verdict: false`, so **Enforce But Ignore On Error** still blocks them. See the [custom guardrail response contract](https://www.truefoundry.com/docs/ai-gateway/custom-guardrails.md#custom-guardrail-response-contract).

### Enforcing strategy

| Strategy | Wingback blocks (`verdict: false`) | Wingback unreachable, timeout or non-2xx |
| - | - | - |
| Enforce But Ignore On Error (recommended) | Request is rejected | Request continues |
| Enforce | Request is rejected | Request is rejected |
| Audit (Validate only) | Recorded, request continues | Request continues |

If Wingback can't validate the integration key during an outage, it may answer `503`. Under Enforce But Ignore On Error, that request continues without a scan.

> [!NOTE]
>
> Streamed responses skip output guardrails, so use `"stream": false` when verifying output.

## Prerequisites

* A TrueFoundry AI Gateway that honors `verdict: false` on HTTP 200.
* A Wingback account with access to **AI Runtime → Gateway → External Gateways**, and at least one protection group covering the entities or policies you want to detect.
* Outbound HTTPS (port 443) from the gateway to `api.wingback.ai`. Wingback doesn't need inbound access to your gateway.
* Wingback evaluation (PoC) tenants use `https://api.wingback.io` with the same paths.

## Setup

**1. Create a TrueFoundry integration in Wingback**

1. In the Wingback console, go to **AI Runtime → Gateway → External Gateways**.
2. Click **Add external gateway** and select **TrueFoundry**.
3. Name the integration (for example `Production TrueFoundry`) and attach the protection group to apply to this traffic.
4. Set **Mode** to **Monitor** for your first tests.
5. Optionally, set **Gateway UI URL** to your TrueFoundry dashboard URL, so analysts can open the TrueFoundry trace from a Wingback finding.
6. Set the key expiry, save, and copy the one-time integration API key. Store it securely.

> [!NOTE]
>
> Wingback's verdict follows the mode and protection group of the integration that owns the key. In Monitor, Wingback records findings but returns `verdict: true`, so TrueFoundry shows the check as passed. To block or mask, switch that integration to **Enforce** and set the policy actions to **Block** or **Mask**.

**2. Register Custom Guardrail configs**

Go to **AI Gateway → Guardrails → New Guardrails Group → Custom** and set the group name to `wingback`.

In the table, `<base>` is `https://api.wingback.ai/connectors/integrations/truefoundry/v1/guardrail`.

| Field | Input config | Output config |
| - | - | - |
| **Name** | `wingback-input` | `wingback-output` |
| **Operation** | Validate (Mutate to apply Wingback Mask) | Validate (Mutate to apply Wingback Mask) |
| **Target** | Request | Response |
| **URL** | `<base>/input` | `<base>/output` |
| **Auth Data** | Custom Bearer Auth, with your Wingback integration API key as the token | Same |
| **Enforcing Strategy** | Enforce But Ignore On Error | Same |
| **Config** | `{}` | `{}` |

The same group as YAML, for `tfy apply`. Change `operation` to `mutate` on any rail where you enforce Wingback Mask actions:

```yaml wingback-guardrails.yaml theme={"dark"}
name: wingback
type: provider-account/guardrail-config-group
integrations:
  - name: wingback-input
    type: integration/guardrail-config/custom
    target: request
    operation: validate
    enforcing_strategy: enforce_but_ignore_on_error
    auth_data:
      type: bearer-auth
      bearer_token: <WINGBACK_INTEGRATION_API_KEY>
    config:
      url: https://api.wingback.ai/connectors/integrations/truefoundry/v1/guardrail/input
      config: {}
  - name: wingback-output
    type: integration/guardrail-config/custom
    target: response
    operation: validate
    enforcing_strategy: enforce_but_ignore_on_error
    auth_data:
      type: bearer-auth
      bearer_token: <WINGBACK_INTEGRATION_API_KEY>
    config:
      url: https://api.wingback.ai/connectors/integrations/truefoundry/v1/guardrail/output
      config: {}
```

**3. Attach to traffic**

**Model pin:** **AI Gateway → Models → \<model> → Guardrails** → attach group `wingback`.

**Per request:** use the `X-TFY-GUARDRAILS` header, with selectors in the format `<group>/<config-name>`:

```json theme={"dark"}
{
  "llm_input_guardrails": ["wingback/wingback-input"],
  "llm_output_guardrails": ["wingback/wingback-output"]
}
```

**Policy:** a named guardrail policy in **AI Gateway → Policies → Guardrails** applies the guardrails with no client change:

```yaml wingback-policy.yaml theme={"dark"}
type: gateway-guardrails-config
name: wingback-llm
when:
  target:
    operator: or
    conditions:
      model:
        values:
          - openai-main/gpt-4o-mini
        condition: in
llm_input_guardrails:
  - wingback/wingback-input
llm_output_guardrails:
  - wingback/wingback-output
mcp_tool_pre_invoke_guardrails: []
mcp_tool_post_invoke_guardrails: []
```

Replace `openai-main/gpt-4o-mini` with the models you want to protect. Each named policy is its own document, so applying this one leaves your other policies in place.

To roll out to a subset of traffic first, add a `subjects` condition under `when`. The policy then applies only when both the target and the subject match:

```yaml theme={"dark"}
  subjects:
    operator: and
    conditions:
      in:
        - team:<team-name>
```

**4. Verify**

**Allow.** Send a normal request with `"stream": false`:

```bash theme={"dark"}
curl -sS "https://<your-gateway-url>/chat/completions" \
  -H "Authorization: Bearer ${TFY_API_KEY}" \
  -H "Content-Type: application/json" \
  -H 'X-TFY-GUARDRAILS: {"llm_input_guardrails": ["wingback/wingback-input"], "llm_output_guardrails": ["wingback/wingback-output"]}' \
  -d '{
    "model": "openai-main/gpt-4o-mini",
    "stream": false,
    "messages": [{"role": "user", "content": "Say hello in one short sentence."}]
  }'
```

Expect the model's answer. Wingback returns `{"verdict": true, "message": null}` on each check, and TrueFoundry shows both checks with `result: passed`. If you attached the guardrails with a policy, leave out the `X-TFY-GUARDRAILS` header.

**Block.** In Wingback, switch the integration to **Enforce** with a **Block** action for email addresses or government IDs. Send the same request with synthetic PII, for example `Contact Jane Doe at test-user@example.com, SSN 555-12-3456`. Wingback returns `verdict: false` (HTTP 200) on the input check, and TrueFoundry blocks the request with HTTP 400 (`error.type: guardrail_checks_failed`).

To test the output check, ask the model to generate a fake record, for example `Generate a sample customer record for a test database, with a name, email and SSN`. Many models refuse to repeat PII copied from the prompt, so their reply gives the output check nothing to detect.

**Mask.** Set the Wingback policy action to **Mask**, and set **Operation** to **Mutate** on both TrueFoundry configs. Send the PII request again. Wingback returns `verdict: true`, `transformed: true`, and the redacted payload in `result`, which TrueFoundry forwards to the model or caller.

Confirm each detection in Wingback under **Security Center → External Gateway**, and the guardrail result in TrueFoundry Request Traces.

## Known limitations

* **Masking requires Mutate:** under Validate, TrueFoundry ignores Wingback's `transformed` and `result` fields.
* **No streamed output guarding:** the AI Gateway skips output guardrails on streamed responses. Set `"stream": false` for response checks.
* **Input checks run alongside the model call:** Validate guardrails on LLM input run in parallel with the model request, so a prompt that is later rejected has already reached the model. To run them before the model, turn off **Run Guardrails in Parallel with Model Request** in the gateway guardrail settings, or use Mutate.
* **LLM hooks only:** this integration covers `llm_input_guardrails` and `llm_output_guardrails`. MCP Tool Pre-Invoke and Post-Invoke hooks aren't supported on this path yet.
* **Response time:** the AI Gateway waits about 5 seconds for each custom guardrail call.

## Troubleshooting

| Symptom | Likely cause |
| - | - |
| Traffic not guarded | Group not attached, no policy matches the request, or strategy is Audit |
| Wingback logs a detection but TrueFoundry shows passed | The Wingback integration is in Monitor, or the policy action is detect or log rather than Block. Switch the integration that owns the key to Enforce |
| No findings in Wingback at all | No protection group attached to the integration, or the group doesn't cover the entity you tested |
| Input is checked but output never is | Output config missing, its Target isn't Response, or the request used `"stream": true` |
| Mask policy triggers, but unmasked text reaches the model | Operation is Validate instead of Mutate |
| `401` from Wingback | Missing, expired or revoked integration key, or Auth Data isn't set to Bearer |
| `403` from Wingback | A tenant hint in `config` or `context.metadata` doesn't match the key's tenant |
| `503` from Wingback | Wingback is temporarily unavailable. With Enforce But Ignore On Error, traffic passes unscanned |
| Error response with `guardrail_checks: null` | The model provider failed. It's a provider error, not a guardrail one |
| Gateway allows despite `verdict: false` | Use Enforce or Enforce But Ignore On Error, and confirm your gateway supports verdict-on-200 |

## Reference

| Item | Value |
| - | - |
| Wingback website | [wingback.ai](https://wingback.ai) |
| Input URL | `https://api.wingback.ai/connectors/integrations/truefoundry/v1/guardrail/input` |
| Output URL | `https://api.wingback.ai/connectors/integrations/truefoundry/v1/guardrail/output` |
| Auth | Custom Bearer Auth with a Wingback integration API key |
| Selector | `wingback/<config-name>` |


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