Skip to content

feat: add ai-neuraltrust-guard plugin - #14309

Draft
alespignaNT wants to merge 1 commit into
apache:masterfrom
alespignaNT:feat/ai-neuraltrust-guard
Draft

alespignaNT wants to merge 1 commit into
apache:masterfrom
alespignaNT:feat/ai-neuraltrust-guard

Conversation

@alespignaNT

Copy link
Copy Markdown

Description

This PR adds ai-neuraltrust-guard, a new AI security plugin that integrates
NeuralTrust TrustGuard with the APISIX AI gateway,
as proposed in #14308. It follows the design of ai-lakera-guard (#13570) and
builds on the ai-protocols layer.

Changes

  • apisix/plugins/ai-neuraltrust-guard.lua, ai-neuraltrust-guard/schema.lua,
    ai-neuraltrust-guard/client.lua: plugin, schema and TrustGuard HTTP client.
    • access: extracts messages with proto.get_messages() (keeping
      system/user/assistant roles) and calls POST /v1/evaluate.
    • lua_body_filter (direction: output|both): evaluates the LLM response,
      including streaming, with the same buffering state machine as ai-lakera-guard.
    • Deny responses are built with proto.build_deny_response(), so they match the
      client's protocol (OpenAI chat, Responses, Anthropic, Bedrock).
    • api_key is in encrypt_fields and supports $secret:// / $env://.
    • Priority 1027.
  • Registered in apisix/cli/config.lua, conf/config.yaml.example, Makefile,
    t/admin/plugins.t and docs/en/latest/config.json.
  • Tests: t/plugin/ai-neuraltrust-guard{,-output,-chain,-secrets}.t (81 cases)
    against a local mock (t/lib/neuraltrust_mock.lua) built from real API responses,
    so CI needs no credentials or external calls.
  • Docs: docs/en/latest/plugins/ai-neuraltrust-guard.md.
  • Optional e2e: t/e2e/ai-neuraltrust-guard/run-e2e.sh runs APISIX in Docker
    against the real TrustGuard API with NEURALTRUST_API_KEY (not used in CI).

Disclosure: I work at NeuralTrust. I validated this end to end against the
production TrustGuard API on APISIX 3.21 (benign prompt allowed, jailbreak blocked).
Payload transformation (redaction/DLP) and MCP tool-call inspection are out of
scope and could follow in separate PRs. Happy to split this PR (input first,
then output/streaming) if maintainers prefer.

Which issue(s) this PR fixes:

Fixes #14308

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

Signed-off-by: Alessandro Pignati <alessandro.pignati@neuraltrust.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant