verdict; the adapter sends the relevant request or response content to
POST /v1/evaluate and maps TrustGuard’s status
to that verdict.
Only traffic routed through a Portkey configuration is evaluated. Direct calls
to a model provider bypass this integration.
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. Implement the webhook adapter
Portkey sends a JSON object containingrequest, response, metadata, and
eventType. For beforeRequestHook, evaluate request.json as input. For
afterRequestHook, evaluate response.json as output. Use the corresponding
text field when a normalized JSON body is not available.
The following function shows the contract conversion. Deploy the equivalent in
your webhook service and return its result as JSON:
default.webhook directly at /v1/evaluate. Portkey’s hook event
contains top-level fields that the Evaluate API does not accept, and the
Evaluate API returns status rather than Portkey’s required verdict.
The sample maps only block to verdict: false. It allows allow, report,
ask, and transform. It does not return transformedData, so redaction is not
supported. Use Block rules for enforcement.
2. Configure the BYOG hooks
Adddefault.webhook to both hook phases. Replace the example adapter URL and
token with your values:
deny: true makes a failed check return HTTP 446. async: false keeps the
check in the request path so Portkey can enforce its result. With only the
before-request hook, Output-phase rules do not run.
Prefer a saved Portkey configuration when the webhook header contains a secret.
An inline configuration sent through x-portkey-config exposes that value to
the calling application.
3. Send consumer and session identifiers
Pass verified identifiers through Portkey metadata so the adapter can populateconsumer_id and session_id:
event.metadata. _user is
Portkey’s documented user identifier, and session_id is its recommended key
for grouping related requests.
4. Configure failure behavior
Portkey’s webhook timeout defaults to 3000 ms. The example raises it to 5000 ms and setsfailOnError: true, so a timeout or non-200 adapter response fails the
check. With deny: true, Portkey returns 446 instead of calling the provider or
returning the completion.
Without failOnError: true, Portkey allows the request when the webhook times
out or returns an error. Use that setting only when you deliberately want to
fail open.
The adapter should return a non-200 response when TrustGuard is unavailable or
rejects its credentials. Returning { "verdict": true } in those cases makes
the integration fail open regardless of the Portkey setting.
5. Verify
Attach the configuration to a request using your existing Portkey client or thex-portkey-config header. With a blocking rule in Enforce mode:
- Send a prompt that triggers the rule.
- Confirm that Portkey returns HTTP 446 and that
hook_resultscontains thetrustguard-inputhook anddefault.webhookcheck. - Confirm that the adapter’s
dataappears under the check’sresponseData, including the TrustGuardtrace_id. - Find the same
trace_idin TrustGuard Activity under the expectedconsumer_idandsession_id.
Reference
Coverage
The adapter evaluates Portkey’s normalized request or response body. Tool
definitions and model-selected tool calls are available only when Portkey
includes them in that body, and a block stops the complete request or response,
not an individual tool event. The adapter does not apply transformed payloads.
Portkey does not support blocking output guardrails on streamed responses, so
use non-streaming responses when output enforcement is required.
A turn with both synchronous hooks makes two TrustGuard evaluations. Each hook
also passes through the adapter, so include both network legs in the timeout and
latency budget.
What is evaluated
Configuration
Attributes
consumer_id: map it from the_uservalue in verified Portkey metadata. Per-consumer policy routing and gates matchingconsumer.iddepend on this value.session_id: map it from a stable, verifiedsession_idvalue in Portkey metadata. Without it, related turns may not be grouped together in Activity.attributes.model.nameandattributes.model.provider: the adapter can read these fromrequest.json.modeland Portkey’sproviderfield.trace_idandrequest_id: return them in the webhook response’sdataobject. Portkey records that object underhook_results[].checks[].data.responseData.
Troubleshooting
Related
- Evaluate API: request and response contract for the adapter
- Policies: Observe and Enforce modes
- Collectors: collector keys and policy assignment
- Portkey BYOG webhooks: webhook request, response, and failure behavior
- Portkey metadata: supported metadata keys and precedence
Experimental: a native
neuraltrust plugin is proposed in
Portkey-AI/gateway#1772, but
it is not part of a released Portkey version.