/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:
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
pip install neuraltrust-trustguard- Call
client.guard()withdirection="input"before the model anddirection="output"on the completion. - Pass
consumer_idandsession_idfor attribution. - Block when
is_blockedis true; forwardtransformed_payloadwhen present.
Node.js SDK
npm install @neuraltrust/trustguard-sdk- Call
client.guard()withdirection: "input"before the model anddirection: "output"on the completion. - Pass
consumerIdandsessionId. - Block when
isBlockedis true; forwardtransformedPayloadwhen present.
REST API
Any language can call the guard endpoint directly (Go users: use the Go SDK instead of hand-rolling). Setdirection on every request — "input" for the prompt,
"output" for the completion — so TrustGuard applies the matching policy phase.
Input (before 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 — setdirection="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; callguard again with direction: "output"
after the model returns.
Tips
- Send documents/links via the
attachmentsargument (folded intopayload.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.