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’sai-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 viainput_type: "response"— see Output guarding. - Block, not mask. The
ai-custom-guardrailplugin 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-guardrailspan (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 theai-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:
ai-proxy and opentelemetry plugins (see the Kong AI Gateway Integration for the base 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:
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:
$(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:Troubleshooting
Guardrail not blocking / no Guardrail span appearing Theai-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
Related Documentation
- Kong AI Gateway Integration — LLM tracing setup for Kong (proxy, OTel export, session grouping)
- Fiddler Guardrails — the Safety and PII checks behind the Kong guardrail adapter
- LiteLLM Guardrails — Fiddler guardrails via the LiteLLM proxy gateway