ai-proxy,
ai-proxy-multi) route requests to model providers such as OpenAI, Anthropic,
and Bedrock.
This integration ships an APISIX plugin, ai-neuraltrust-guard, that sends the
conversation to TrustGuard before the model is called and, optionally, the
completion before the client receives it. It works with every provider
supported by AI Proxy and needs no application changes. Direct calls to a
provider do not pass through APISIX.
ai-neuraltrust-guard is proposed for inclusion in Apache APISIX
(apache/apisix#14309). Until it
is released, install it as an external plugin as described below. Once it ships
with APISIX, you only enable it and skip step 2.Integration capabilities
A
transform verdict is applied (apply_transform, default true): the request
is rewritten before the model is called, and the completion is rewritten before
the client receives it. MCP tool calls are not evaluated.
Before you start
Set up the policy in TrustGuard
A collector with no policy returns
allow and inspects nothing, with no
warning. Set up the policy before anything else.- In Detectors, create the detectors the policy needs. A typical set is Prompt Guard, Toxicity Detection, and a Custom Moderation detector for your own topics.
-
In Policies, create a policy and add the rules on its Detectors tab:
Use Block for Prompt Guard, Indirect Prompt Injection and secrets. Use Transform for Data Loss Prevention PII (email, card, IBAN) so the plugin can mask them. A Transform action is applied when
apply_transformis true (the default). - On the policy’s Collectors tab, attach the APISIX collector with Routing mode Default. You can do the same from the collector’s Policies tab.
- Set Basics → Enforcement mode to Observe for the first run. Findings appear in Activity without affecting traffic. Switch to Enforce after reviewing them.
Install the plugin on APISIX
APISIX loads plugins that live outside its own directory through
The folder must keep this layout:Then edit With Docker, mount the folder and the config:On Kubernetes, mount the same three files at A JSON schema means it is loaded. A 404 means the plugin is not in the
apisix.extra_lua_path. No change to APISIX is needed. Download the three
files into /opt/neuraltrust/apisix/plugins on every APISIX node:conf/config.yaml:/opt/neuraltrust/apisix/plugins
(for example from a ConfigMap) and set extra_lua_path in the APISIX
configuration. Restart APISIX, then confirm the plugin is loaded:plugins list or the files are not under extra_lua_path.Store the collector key
Do not paste the key into the route. Set it as an environment variable on every
APISIX node and reference it:The route then uses
"api_key": "$env://NEURALTRUST_API_KEY". APISIX also
supports $secret:// references (Vault, AWS, GCP) for the same field.Enable the plugin on a route
Add the plugin next to Put an auth plugin (
ai-proxy on each route to protect. It runs after
ai-proxy (priority 1027).key-auth, jwt-auth, openid-connect) on the same
route so findings in Activity map to a consumer. With send_consumer_id
(default true) the plugin sends the APISIX consumer name. Send a real
conversation ID in a header and set session_id_header to its name so the
Multi-turn Guard can follow a conversation.Test it
A benign prompt passes:A jailbreak is blocked. The denial is a normal completion (HTTP 200) so SDKs
show it as the assistant’s message:Each verdict is in the APISIX error log with its In Enforce mode a blocked request never reaches the model. In Observe
mode the request passes and the finding appears in Activity.
trace_id, which you can
search in Activity. Set nginx_config.error_log_level: info to also log
allow verdicts:Configuration
Behavior and limits
- Streaming. With
direction: inputa stream reaches the client live. Withoutputorboththe plugin buffers the stream, evaluates the assembled completion once, then releases it in one piece or replaces it with the refusal. The client sees only SSE comments (:) until the end. This also works when another buffering guard plugin, such asai-lakera-guard, is on the route. - Interrupted streams. If the stream ends without a complete assistant
message (the upstream is cut by
max_response_bytesormax_stream_duration_ms, or the SSE is truncated), the plugin followsfail_open: it blocks by default. A turn made only of tool calls has no text to evaluate and passes. - Redaction. A
transformverdict is applied (apply_transform: trueby default). The rewritten body has the same shape as the request, with values replaced by tokens such as[MASKED_CC]. Setapply_transform: falseto only log, or addtransformtoblock_onto deny. If the rewritten body cannot be applied, the plugin followsfail_open. - Cost.
direction: bothis two evaluations per model turn. The response is evaluated only if the request passed. - Models only. The plugin evaluates calls that go through
ai-proxyorai-proxy-multi. MCP tool calls are not evaluated. - Sessions. The Multi-turn Guard keeps history per
session_id. After a blocked turn, later turns in the same session are also blocked. Without a session header, every call is a new session.
Related
- Evaluate API: the endpoint the plugin calls
- Policies: Observe and Enforce, gates, and detector rules
- Collectors: collector keys and policy routing
- Apache APISIX plugin development:
extra_lua_path - Apache APISIX secrets:
$env://and$secret://