Skip to main content

LiteLLM Guardrails

Overview

Fiddler implements the LiteLLM Generic Guardrail API spec, allowing you to plug Fiddler’s guardrails directly into a LiteLLM proxy gateway. Once configured, every LLM request routed through the proxy is checked by Fiddler before it reaches the model. Fiddler checks for:
  • Secrets — API keys, tokens, credentials, and connection strings in prompts
  • PII — Personal identifiable information (names, emails, phone numbers, SSNs, credit cards, etc.)
Each check can independently block or redact — see Check Behavior for details.

How It Works

LiteLLM calls the Fiddler endpoint with the extracted text from the request (or response). Fiddler returns one of three actions:

Supported Modes

Fiddler supports all three LiteLLM guardrail modes. Set mode in your proxy config to one or more of:
during_call runs the guardrail concurrently with the LLM call — the response is held until the check completes, but latency is hidden behind the LLM round-trip. Use it when you want lower end-to-end latency and don’t need input redaction (block-only is sufficient).
You can combine modes. For example, mode: [pre_call, post_call] scans both input and output:

Supported Endpoints

The guardrail runs on all LiteLLM proxy endpoints that carry text content, including /v1/chat/completions (OpenAI format) and /v1/messages (Anthropic format). LiteLLM extracts text from the request and forwards it to the Fiddler endpoint regardless of the upstream provider format.

What Gets Scanned

  • Free-text messages — user, assistant, and system messages. PII/secrets are redacted in place (e.g. [REDACTED EMAIL_ADDRESS]).
  • Tool-call arguments — structured JSON in tool_calls[].function.arguments. Detections are always blocked (cannot safely redact inside structured JSON — see Tool Call Handling).

Quick Start

Step 1: Configure LiteLLM

Add the Fiddler guardrail to your LiteLLM config.yaml:
LiteLLM appends /beta/litellm_basic_guardrail_api to api_base automatically. The full endpoint called will be https://<your-fiddler-instance>/v3/guardrails/litellm/beta/litellm_basic_guardrail_api.

Step 2: Start the proxy

Step 3: Verify

Send a request with a known secret:
The secret will be redacted to [REDACTED ANTHROPIC_API_KEY] before the request reaches the model.

Per-Request Control

With default_on: true (the recommended config above), the guardrail runs on every request automatically. You can also control it per request.

Selective activation (default_on: false)

Set default_on: false in the proxy config, then activate the guardrail on individual requests by passing guardrails in the request body:
Requests without "guardrails": ["fiddler"] will bypass the guardrail entirely.

Check Behavior

Each check is configured entirely in the LiteLLM proxy’s additional_provider_specific_params:
  • enabled (true / false) — whether the check runs at all.
  • mode (redact / block) — what happens when a detection is found. Default is redact for PII and secrets.
  • threshold and entities — detection sensitivity.
If any of pii or secrets is specified in additional_provider_specific_params, only the checks explicitly listed with enabled: true will run. To tune one check without silently disabling the other, list both keys with explicit enabled: true or enabled: false.

Secrets

Detects credentials, API keys, and tokens.

PII

Detects personal identifiable information. Entities checked by default include: person, email, phone number, social security number, credit card number, bank account number, passport number, driver's license number, date of birth, address, ip address, iban, cvv, cvc, tax identification number, digital signature, license plate number, postal code, and more. For the complete list see the PII Detection tutorial.

Tool Call Handling

When an LLM’s tool_calls contain PII or secrets, Fiddler always blocks rather than redacts. Why: Tool call arguments are structured JSON that the downstream application will parse and execute. Replacing a value like an email address with [REDACTED EMAIL_ADDRESS] would cause send_email to attempt delivery to a nonsensical address — producing unpredictable behavior that is worse than blocking outright. Example — blocked tool call:
Fiddler returns:
LiteLLM then translates this into an error for the client (HTTP 400 on LiteLLM ≥ 1.88.0, HTTP 500 on earlier versions).

Tool Results

Fiddler does not claim redaction coverage for tool results. Whether tool result content reaches the scanner depends on the LiteLLM gateway: LiteLLM must include the tool result in the texts[] it forwards to Fiddler. This is not guaranteed for all gateway configurations or versions, and is known not to work on customer-managed or self-hosted gateways that do not extract role:tool / tool_result messages into texts[]. Additionally, tool results are typed as any in the GenAI semantic conventions — they can be plain strings, JSON objects, or arrays. Even when the text does reach the scanner, in-place character-span redaction on a serialized JSON payload is not safe if the downstream application re-parses the result as structured data. For reliable protection against secrets in tool output, use mode: block on secrets and treat tool result content as untrusted.

Failure Mode

Two settings control what happens when the guardrail cannot complete a check — one at the LiteLLM proxy level, one at the Fiddler endpoint level. Both should be set for end-to-end fail-closed.

unreachable_fallback (LiteLLM proxy)

Controls what happens when the Fiddler endpoint is unreachable (network error, HTTP 502/503/504).
This is a standard LiteLLM Generic Guardrail API setting.

failure_mode (Fiddler endpoint)

Controls what happens when an internal check fails to complete — an inference timeout, an inference server error, or an unexpected exception in the detection pipeline. The LiteLLM proxy cannot see these failures because the Fiddler endpoint still returns HTTP 200.
The default is open for backward compatibility. For security-sensitive deployments, set failure_mode: closed. When both unreachable_fallback: fail_closed and failure_mode: closed are set, no request can bypass scanning — whether the failure is at the transport or detector level.

Limits & Timeouts

Text Length

The maximum total text length scanned per request is controlled by the GUARDRAILS_MAX_TEXT_LENGTH environment variable on the Fiddler server (default: 50,000 characters). Messages are concatenated until this cap is reached; text beyond the cap is handled as follows:

Timeouts

The guardrail check has a single customer-facing timeout: the wall-clock deadline for the whole check pipeline — how long the endpoint blocks before returning. Set it per request via timeout (seconds) in additional_provider_specific_params:
What you set is what you get — there is no hidden padding. Omitted or invalid values fall back to the default (12s); values above the maximum are clamped to 60s. When the deadline is reached before the checks complete, the outcome is governed by failure_mode — under open the request proceeds unscanned, under closed it is blocked.
The internal inference-call timeouts (GUARDRAILS_GATEWAY_READ_TIMEOUT, default 10s, and GUARDRAILS_GATEWAY_CONN_TIMEOUT, default 3s) are server-side plumbing for the connection to the detection models. They are lower than the wall-clock timeout and are not part of the customer-facing config.

Observed Behavior

Minimum required version: LiteLLM ≥ 1.88.0. Earlier versions return HTTP 500 for all guardrail blocks due to a bug in GuardrailRaisedException (missing status_code attribute). The Fiddler team identified and fixed this upstream in BerriAI/litellm#27617. The fix shipped in LiteLLM 1.88.0. On 1.88.0+, blocked requests correctly return HTTP 400.

Client-Facing Error Body

When a request is blocked, LiteLLM returns an error to the client. Your application should handle this shape:
The message field contains the blocked_reason from Fiddler’s response, prefixed by LiteLLM with the guardrail name. HTTP status is 400 on LiteLLM ≥ 1.88.0.

API Reference

Endpoint

Authentication: Authorization: Bearer <your-fiddler-api-key>

Request

Only texts and tool_calls[].function.arguments are scanned by guardrail checks. The remaining fields are accepted for LiteLLM protocol compatibility.

Response

Fields with null values are omitted from the wire (exclude_none=True). The response shape varies by action: