Skip to main content
When you own the application, integrate TrustGuard directly around your model calls. This gives you full control over what to inspect and how to enforce, and works with any model provider. Create an API key on the collector first. Prefer the official SDKs over hand-rolled HTTP — they take the base URL and call /v1/evaluate for you: The response carries a status (allow / report / transform / block); the SDKs expose is_blocked / isBlocked (true when status == "block") and the transformed_payload for masked content.

Input vs output (direction)

TrustGuard does not infer whether a payload is a prompt or a completion. Every guard() / /v1/evaluate call must set direction: A policy can attach different detectors (and actions) to each phase — for example jailbreak / prompt injection on input, and PII or toxicity on output. Only rules whose phase matches the request’s direction run; the other phase is skipped for that call. To cover both sides of a turn you call TrustGuard twice:
If you only send input, output-phase detectors never evaluate. If you omit direction, it defaults to input. When traffic goes through TrustGate instead of your app, the gateway sets direction for you (input on the request path, output on the response path). Application integrations must set it explicitly. See How it works for how rules are filtered by direction.

Python SDK

  1. pip install neuraltrust-trustguard
  2. Call client.guard() with direction="input" before the model and direction="output" on the completion.
  3. Pass consumer_id and session_id for attribution.
  4. Block when is_blocked is true; forward transformed_payload when present.

Node.js SDK

  1. npm install @neuraltrust/trustguard-sdk
  2. Call client.guard() with direction: "input" before the model and direction: "output" on the completion.
  3. Pass consumerId and sessionId.
  4. Block when isBlocked is true; forward transformedPayload when present.

REST API

Any language can call the guard endpoint directly (Go users: use the Go SDK instead of hand-rolling). Set direction on every request — "input" for the prompt, "output" for the completion — so TrustGuard applies the matching policy phase. Input (before the model):
Output (after the model):

Python middleware (FastAPI / Django / Flask)

Guard inbound user traffic in-process with a middleware in front of your AI routes. Middleware typically covers the request path — set direction="input". Guard the model response in the route or service layer with direction="output".

Node.js middleware (Express / Next.js)

Same pattern: middleware for input; call guard again with direction: "output" after the model returns.

Tips

  • Send documents/links via the attachments argument (folded into payload.attachments) to engage the document and URL analyzers — see the Evaluate API for the attachment + SSRF rules.
  • On a detector infrastructure error TrustGuard follows your deployment’s fail-open / fail-closed setting — decide whether to hold traffic on errors accordingly.