The AI GCP Model Armor Policy responds to a blocked request or response according to its rejection mode.
Use config.rejection_mode to control how AI Gateway responds to a blocked request:
|
Mode
|
Status code
|
Response body
|
none (default)
|
400
|
A JSON error with the block message, for example {"error": {"message": "..."}}.
The response omits the guardrail’s name.
Clients can tell it apart from a malformed request only by its message, because the status code is the same.
|
stealth
|
403
|
A generic JSON error, {"error": {"message": "request forbidden"}}.
The response hides all guardrail details.
|
verbose
|
403
|
A structured JSON error that names the Policy that blocked the request and the reason.
See Verbose response.
|
Use none or stealth for clients outside your organization, so responses don’t reveal how your guardrails are configured.
Use verbose in development or for trusted internal clients, to see why a request was blocked.
In verbose mode, the response always has the status code 403 and the error code GUARDRAIL_BLOCKED.
Clients can check the error.code field to tell a guardrail rejection apart from other errors:
type: Always guardrail_rejected.
plugin: The type of the Policy that blocked the request.
reason: Why the request was blocked.
code: Always GUARDRAIL_BLOCKED.
detail: Additional context about the match. This field is only present when the Policy has details to report.
When a guardrail blocks a streaming response, the final chunk of the stream has finish_reason set to blocked_by_guard.
The chunks that the guardrail already evaluated and sent are not recalled, so the HTTP status code of the response remains 200.
The rejection_mode setting changes what the chunk reports:
none: The delta.content field contains the block message.
stealth: The delta.content field contains the message request forbidden.
verbose: The delta.content field contains the block reason, and choices[0] also includes a guardrail_result object with the same fields as the verbose response.
In none mode, the response body is the plain message set in config.request_failure_message for requests or config.response_failure_message for responses.
The following response is the body for a request blocked in none mode:
{
"message": "Request was filtered by GCP Model Armor",
"error": true
}
In verbose mode, reason is the type of the Model Armor filter that matched, and detail lists the filter results that GCP Model Armor returned.
For example, a prompt injection attempt returns the following response:
{
"error": {
"type": "guardrail_rejected",
"plugin": "ai-gcp-model-armor",
"reason": "pi_and_jailbreak.piAndJailbreakFilterResult",
"code": "GUARDRAIL_BLOCKED",
"detail": [
{
"checkType": "pi_and_jailbreak.piAndJailbreakFilterResult",
"confidenceLevel": "MEDIUM_AND_ABOVE"
}
]
}
}
To return this response, set config.rejection_mode to verbose:
curl -X POST https://{region}.api.konghq.com/v1/ai-gateways/{AIGatewayId}/policies \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"display_name": "AI GCP Model Armor - Verbose Rejection",
"name": "ai-gcp-model-armor",
"type": "ai-gcp-model-armor",
"config": {
"project_id": "'$PROJECT_ID'",
"location_id": "us-central1",
"template_id": "'$TEMPLATE_ID'",
"gcp_use_service_account": true,
"gcp_service_account_json": "'$GCP_SERVICE_ACCOUNT_JSON'",
"rejection_mode": "verbose"
}
}
'
ai_gateway_policies:
- ref: ai-gcp-model-armor
ai_gateway: !lookup {id: !env AI_GATEWAY_ID}
display_name: AI GCP Model Armor - Verbose Rejection
name: ai-gcp-model-armor
type: ai-gcp-model-armor
config:
project_id: !env PROJECT_ID
location_id: us-central1
template_id: !env TEMPLATE_ID
gcp_use_service_account: true
gcp_service_account_json: !env GCP_SERVICE_ACCOUNT_JSON
rejection_mode: verbose
Make sure to replace the following placeholders with your own values:
-
AI_GATEWAY_ID: The id of your AI Gateway.
-
!env GCP_SERVICE_ACCOUNT_JSON: The JSON key of a GCP service account with access to the Model Armor template.
-
!env PROJECT_ID: Your GCP project ID.
-
!env TEMPLATE_ID: Your template ID.