Skip to main content
Kong Gateway applies plugins for authentication, rate limiting, logging, and other controls to API routes. Its AI Proxy plugin exposes a route that forwards prompts to a configured model provider and returns completions. This integration evaluates traffic on routes that use AI Proxy without client changes. Applications that call a provider directly bypass it, and verdicts apply to the complete request or response rather than an individual tool call.

Integration capabilities

Before you start

Start with the policy in Observe mode. Findings appear in Activity without affecting traffic. Switch to Enforce after reviewing the results. See Policies.

1. Create a collector API key

On the Kong collector, open Auth and create a key. It is shown once. The key identifies the collector and its assigned policy; the request body does not need a collector ID.

2. Configure AI Proxy on the route

Attach AI Proxy (or AI Proxy Advanced) to the route you want to protect and confirm model calls flow through it. Until they do, ai-custom-guardrail has nothing to evaluate.

3. Add the guardrail plugin

ai-custom-guardrail calls an HTTP endpoint with the text of the AI request and maps the response to a decision. Point it at POST /v1/evaluate and send the collector key as a bearer token:
Request-template functions receive Kong’s built-in conf, content, and source values in that order. trustguard_direction reads the third argument and converts INPUT or OUTPUT to the lowercase value accepted by /v1/evaluate, so guarding_mode: BOTH selects the correct policy phase on each pass. Add consumer_id and session_id to the same body block. Map consumer_id from Kong’s verified consumer identity and session_id from a stable, verified conversation ID. These values determine how Activity groups events. See Attributes.

4. Map the verdict to a block

The check_response function maps resp.status == "block" to the plugin’s boolean block field. The caller receives the configured block_message.
This route does not support redaction. A masking policy returns transform, which the boolean mapping does not block or apply. The request continues without masking, while the console records the verdict. Rewriting the body requires a downstream plugin. Use Block rules on a Kong route.
An ask verdict is also allowed and recorded because the gateway cannot prompt a user. Every status other than block passes.

5. Configure response evaluation

The sample sets guarding_mode: BOTH. Kong runs the plugin for the request and response and passes the current phase to trustguard_direction. Use guarding_mode: INPUT for request-only evaluation. In that mode, Output-phase rules do not run.

6. Verify

  1. Put the policy in Enforce and send a prompt through the guarded route that trips a rule.
  2. Confirm that the caller receives Blocked by TrustGuard.
  3. Confirm the event in TrustGuard Activity, under the consumer_id you mapped from X-Consumer-ID.
Then repeat with a response-side rule and confirm that the output pass runs.

Reference

Coverage

The plugin evaluates requests and responses but does not support redaction. concatenate_all_content flattens message roles into one string. Validate streaming-response behavior for your Kong deployment before relying on it. Each evaluated direction adds one round trip to {TRUSTGUARD_URL}.

What is evaluated

Every call is POST /v1/evaluate with the collector key as a bearer token, and the policy’s detectors decide the verdict. Every verdict is request-level: a block stops the whole request, never one part of it.

Configuration

Configure the integration in the plugin’s config block: The mapping reads only status. allow, report, ask, and transform all pass. Findings remain available in Activity.

Attributes

  • consumer_id: Kong’s X-Consumer-ID. It is what per-consumer policy routing keys on, so without it every caller shares the collector’s default policy.
  • session_id: a stable, verified conversation ID. Do not send an empty value if you need reliable grouping in Activity.
  • Both are body fields that you must map from trusted Kong or application data.

Troubleshooting

  • Evaluate API: request and response contract for the endpoint the plugin calls
  • Policies: Observe and Enforce modes, including gate configuration
  • Collectors: collector keys and policy resolution
  • Kong AI Proxy: Kong reference for the plugin this integration depends on
  • Kong AI Custom Guardrail: configuration, built-in variables, and minimum version