Skip to main content

Overview

Kong can enforce Fiddler Guardrails on prompts before they reach the model — blocking unsafe content, PII, and secrets at the gateway. This uses Kong’s ai-custom-guardrail plugin, which calls Fiddler’s Kong guardrail adapter (/v3/guardrails/kong) on each request and emits a connected Guardrail span in the same trace as the LLM span. This page covers guardrails only. For LLM tracing setup (the ai-proxy and opentelemetry plugins, session grouping, and span mapping), see the Kong AI Gateway Integration.
Guardrails require Kong Gateway Enterprise 3.14+ai-custom-guardrail is an Enterprise plugin. (Tracing alone works on OSS Kong 3.13+.) The guardrail is an additional plugin on the same route you configured for tracing.

How It Works

  • Pre-call input guarding (post-call also supported). Each prompt is checked before the LLM is called (guarding_mode: INPUT); safe prompts continue to the model, and unsafe ones are blocked with HTTP 400 before the model is called. The adapter also supports post-call output guarding via input_type: "response" — see Output guarding.
  • Block, not mask. The ai-custom-guardrail plugin can only allow or block — it cannot substitute a redacted body. So detected PII and secrets are blocked, not masked. (This differs from the LiteLLM integration, where PII can be redacted.)
  • Connected guardrail span. Each check emits a fiddler-guardrail span (fiddler.span.type: guardrail) in the same trace as the LLM span, so the guardrail decision appears next to the model call in Fiddler.

Configuration

Add the ai-custom-guardrail plugin to the same openai-service route you configured for tracing, alongside ai-proxy and opentelemetry. It sends each prompt to Fiddler’s /v3/guardrails/kong adapter, blocks when Fiddler returns block: true, and runs a small Lua check function that emits the connected Guardrail span:
The check Lua function requires KONG_UNTRUSTED_LUA=on (the same setting the session-grouping pre-function needs). Without it Kong refuses to load the inline Lua and the Guardrail span is never emitted.
Add this plugin to the same declarative Kong config that holds your ai-proxy and opentelemetry plugins (see the Kong AI Gateway Integration for the base setup).
The ${FIDDLER_URL} and ${FIDDLER_API_KEY} values are placeholders. Kong does not read environment variables from its declarative config, so replace each ${...} with your actual value before starting Kong — otherwise Kong fails to start. See Step 2 of the tracing setup.

Check Behavior

Kong extracts the text (the prompt, or the buffered model output) and posts it to the adapter, which runs the appropriate Fiddler checks and returns a block decision: Request
Response — allowed:
Response — blocked (unsafe, PII, or secrets):
Kong’s check function maps block → whether to reject the request and reason → the client-facing block_message. The underlying checks are the same Safety and PII checks described in Fiddler Guardrails, plus secrets detection.

Output Guarding

The Configuration above guards the input prompt (guarding_mode: INPUT, sending input_type: "request"). The Fiddler adapter also supports post-call output guarding — when it receives input_type: "response" it runs PII and secrets checks on the model output (Safety applies to input only, so unsafe-content classification is not re-run on the output). To guard the output, add a second ai-custom-guardrail plugin in guarding_mode: OUTPUT whose request body sets input_type: "response" — in output mode Kong’s $(content) resolves to the model’s response:
Here $(resp.block) and $(resp.reason) map directly to the adapter’s response fields, so a blocked output returns HTTP 400 to the caller with the block reason. To also emit a connected Guardrail span on the output path, add a functions.check block like the one in the input configuration. As with the input config, replace the ${FIDDLER_URL} and ${FIDDLER_API_KEY} placeholders with your actual values — Kong does not interpolate environment variables from its declarative config (see Step 2 of the tracing setup).
Verified on Kong Gateway Enterprise 3.14: in guarding_mode: OUTPUT, $(content) resolves to the model response and input_type: "response" is sent to the adapter, which runs PII/secrets checks on the output and blocks when detections are found (Safety is applied to input only). Re-verify after major Kong upgrades, since Gen AI OTel/guardrail behavior is still evolving.

Verifying Guardrails

Send a request through Kong’s OpenAI-compatible endpoint. A prompt containing PII or unsafe content is blocked at the gateway with HTTP 400; a benign prompt returns a normal completion:
In Fiddler, allowed prompts show an LLM span and a Guardrail span in one trace; blocked prompts show a Guardrail span carrying the block reason (with no LLM span, since the model was never called).

Troubleshooting

Guardrail not blocking / no Guardrail span appearing The ai-custom-guardrail plugin is Kong Enterprise 3.14+ only — it is silently absent on OSS Kong. Confirm you are on Kong Enterprise 3.14+, that KONG_UNTRUSTED_LUA=on is set (required for the check function that emits the span), and that the ${FIDDLER_URL}/v3/guardrails/kong URL and Authorization header in the plugin config are correct. Check your Kong logs for errors calling the adapter. Prompt missing from the LLM span when guardrails are enabled Kong’s Gen AI OTel tracing is still Tech Preview. When an ai-custom-guardrail plugin shares the route, Kong 3.14.x drops gen_ai.input.messages from the LLM span and degrades gen_ai.output.messages to the raw response-body map. The check function above works around this by reading the original request with kong.request.get_raw_body() and stamping the prompt onto the Guardrail span as gen_ai.llm.input.user, so the prompt is still visible in the trace. Re-verify this behavior after Kong upgrades.

Known Limitations