The AI Azure Content Safety 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.
For example, a request that breaches a category threshold returns the following response in verbose mode.
The detail.categories field lists each breached category with its detected severity and the configured threshold:
{
"error": {
"type": "guardrail_rejected",
"plugin": "ai-azure-content-safety",
"reason": "breached category [Violence] at level 2",
"code": "GUARDRAIL_BLOCKED",
"detail": {
"categories": [
{
"category": "Violence",
"severity": 4,
"threshold": 2
}
],
"blocklists": {}
}
}
}
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 Azure Content Safety - Verbose Rejection",
"name": "ai-azure-content-safety",
"type": "ai-azure-content-safety",
"config": {
"content_safety_url": "https://my-acs-instance.cognitiveservices.azure.com/contentsafety/text:analyze",
"content_safety_key": "'$AZURE_CONTENT_SAFETY_KEY'",
"categories": [
{
"name": "Violence",
"rejection_level": 2
}
],
"rejection_mode": "verbose"
}
}
'
ai_gateway_policies:
- ref: ai-azure-content-safety
ai_gateway: !lookup {id: !env AI_GATEWAY_ID}
display_name: AI Azure Content Safety - Verbose Rejection
name: ai-azure-content-safety
type: ai-azure-content-safety
config:
content_safety_url: https://my-acs-instance.cognitiveservices.azure.com/contentsafety/text:analyze
content_safety_key: !env AZURE_CONTENT_SAFETY_KEY
categories:
- name: Violence
rejection_level: 2
rejection_mode: verbose
Make sure to replace the following placeholders with your own values: