Skip to main content

Handle Policy Blocks and Gateway Errors

Gateway-generated failures use the public error envelope. Some request families can preserve an upstream status and error body. This page shows how to distinguish stable Verdictan fields from provider-specific details.

Public error envelope

Verdictan returns JSON in this shape:

{
"error": {
"message": "Request blocked by policy: prompt_injection.detected",
"type": "invalid_request_error",
"param": null,
"code": "content_policy_violation"
}
}

Use error.type and error.code for application logic. Use error.message as descriptive text for the user.

Frequent error categories

ConditionStatuserror.typeerror.code
Buffered request or response blocked by policy400invalid_request_errorcontent_policy_violation
Header/body session ID mismatch422invalid_request_errorsession_id_mismatch
Missing, invalid, revoked, or expired API token401authentication_errorinvalid_api_token or tokens.expired
Token budget exhausted402cost_budget_exceededtokens.budget_exhausted
Token request limit exhausted403access_deniedtokens.request_limit_exhausted
Gateway-generated provider failureroute-specific 4xx or 5xxprovider_errorcan be null
Gateway runtime failure500internal_errorcan be null

Policy block example

For a non-streaming request, a policy block returns HTTP 400 and the standard envelope:

{
"error": {
"message": "Request blocked by policy: prompt_injection.detected",
"type": "invalid_request_error",
"param": null,
"code": "content_policy_violation"
}
}

Handle this case as a governed refusal, not as a transport failure.

For a streaming request, the HTTP stream can start before an output policy blocks the response. Then, the status stays 200. The gateway sends the policy error in the SSE body. Examine the stream events. Do not use only the initial status.

Invalid request example

Validation failures usually identify an incorrect payload shape or request option:

{
"error": {
"message": "Body session_id must match the configured session header when both are present",
"type": "invalid_request_error",
"param": null,
"code": "session_id_mismatch"
}
}

Correct the client payload. Then, retry the request.

Provider failures

Provider failures have different shapes. Some request families preserve the provider status and body. Other paths create a provider_error envelope. The request family and failure location control this behavior.

Retry a provider failure only when the status lets you retry. The operation must be idempotent. The workflow must be able to wait. Do not change a failed provider call to a silent success.

How to debug the failure

  1. Run verdictan events tail --since 10m --json.
  2. Reproduce the request.
  3. For a policy failure, run verdictan events tail --since 10m --verdict blocked --json.
  4. Match the Event request ID to the client response.
  5. Use the Event as delivered control-plane evidence.
  6. Open History only when you enable capture and request or session details.
  7. Use Trail or exports when you must send an evidence package.

Application guidance

  • Select behavior from error.type and error.code, not from free-form message text.
  • Do not retry invalid_request_error or content_policy_violation blindly.
  • For provider errors, examine the HTTP status and returned body. The provider can supply the body.
  • Retry only when the request is idempotent and your caller can wait.
  • Log the request identifier and returned error fields together. This helps you connect application logs to Verdictan evidence.

Next steps