What happened?
"By default, when Bedrock guardrails block content, LiteLLM raises an HTTP 400 exception. However, you can disable this behavior by setting disable_exception_on_block: true" - https://docs.litellm.ai/docs/proxy/guardrails/bedrock#disabling-exceptions-on-bedrock-block
Using bedrock guardrails in litellm causes issues in client applications such as claude-code and open web ui when disable_exception_on_block is set to true. When this setting is set to false however, litellm will unnecessarily invoke the model with the intercepted message for blocked prompts from the Guardrail, leading to unnecessary token usage.
STEPS TO REPRODUCE
- Configure Bedrock Guardrail with a message shown for blocked prompts, for example "I can not answer this question"
- Add guardrail to LiteLLM
mode: [pre_call, post_call]
disable_exception_on_block: true
default_on: true
- Invoke model with prompt that should be blocked
curl https://${host}/v1/chat/completions -H "Authorization: Bearer ${api_key}" -H "Content-Type: application/json" -d '{"model": "bedrock-claude-3.7-sonnet","messages": [{"role": "user", "content": "${Restricted prompt}"}],"guardrails": ["${guardrail_name}"]}'
Observed behavior
Prompt -> guardrail intercepted -> guardrail response -> model -> model response -> user
The guardrail successfully intercepts the blocked prompt, but instead of responding with the configured message, the configured message is sent to the llm
Expected behavior
Prompt -> guardrail intercepted -> guardrail response -> user
"When exceptions are disabled, instead of receiving an error, you'll get a successful response containing the Bedrock guardrail's modified/blocked output." -> https://docs.litellm.ai/docs/proxy/guardrails/bedrock#disabling-exceptions-on-bedrock-block
Relevant log output
"guardrail_information": {
"duration": 0.788103,
"end_time": 1753873582.723875,
"start_time": 1753873581.935773,
"guardrail_mode": [
"pre_call",
"post_call"
],
"guardrail_name": "br-guardrail",
"guardrail_status": "success",
"guardrail_response": {
"model": "bedrock-claude-3.7-sonnet",
"messages": [
{
"role": "user",
"content": "I can not answer this question"
}
]
Are you a ML Ops Team?
No
What LiteLLM version are you on ?
v1.74.7
Twitter / LinkedIn details
No response
What happened?
"By default, when Bedrock guardrails block content, LiteLLM raises an HTTP 400 exception. However, you can disable this behavior by setting disable_exception_on_block: true" - https://docs.litellm.ai/docs/proxy/guardrails/bedrock#disabling-exceptions-on-bedrock-block
Using bedrock guardrails in litellm causes issues in client applications such as claude-code and open web ui when disable_exception_on_block is set to true. When this setting is set to false however, litellm will unnecessarily invoke the model with the intercepted message for blocked prompts from the Guardrail, leading to unnecessary token usage.
STEPS TO REPRODUCE
mode: [pre_call, post_call]
disable_exception_on_block: true
default_on: true
curl https://${host}/v1/chat/completions -H "Authorization: Bearer ${api_key}" -H "Content-Type: application/json" -d '{"model": "bedrock-claude-3.7-sonnet","messages": [{"role": "user", "content": "${Restricted prompt}"}],"guardrails": ["${guardrail_name}"]}'Observed behavior
Prompt -> guardrail intercepted -> guardrail response -> model -> model response -> user
The guardrail successfully intercepts the blocked prompt, but instead of responding with the configured message, the configured message is sent to the llm
Expected behavior
Prompt -> guardrail intercepted -> guardrail response -> user
"When exceptions are disabled, instead of receiving an error, you'll get a successful response containing the Bedrock guardrail's modified/blocked output." -> https://docs.litellm.ai/docs/proxy/guardrails/bedrock#disabling-exceptions-on-bedrock-block
Relevant log output
Are you a ML Ops Team?
No
What LiteLLM version are you on ?
v1.74.7
Twitter / LinkedIn details
No response