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:
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
Thecheck_response function maps resp.status == "block" to the plugin’s
boolean block field. The caller receives the configured block_message.
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 setsguarding_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
- Put the policy in Enforce and send a prompt through the guarded route that trips a rule.
- Confirm that the caller receives
Blocked by TrustGuard. - Confirm the event in TrustGuard Activity, under the
consumer_idyou mapped fromX-Consumer-ID.
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’sconfig block:
The mapping reads only
status. allow, report, ask, and transform all
pass. Findings remain available in Activity.
Attributes
consumer_id: Kong’sX-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
Related
- 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