fix(guardrails): use plural key in get_disable_global_guardrail

Rename disable_global_guardrail → disable_global_guardrails to match
the key name used by litellm_pre_call_utils.py, the API endpoints,
and the UI when propagating key/team metadata.

The singular form was introduced in PR #16983 and has never matched
the plural form written by the rest of the codebase, so the feature
silently did nothing.

Re-applies fix originally from #25488. Original commit could not be
merged due to missing signature.

Co-Authored-By: Remi Mabon <remi.mabon@redcare-pharmacy.com>
This commit is contained in:
Ryan Crabbe 2026-04-11 17:35:50 -07:00
parent 01b9b50b43
commit ef38c665ca
No known key found for this signature in database
3 changed files with 9 additions and 9 deletions

View file

@ -259,11 +259,11 @@ class CustomGuardrail(CustomLogger):
"""
Returns True if the global guardrail should be disabled
"""
if "disable_global_guardrail" in data:
return data["disable_global_guardrail"]
if "disable_global_guardrails" in data:
return data["disable_global_guardrails"]
metadata = data.get("litellm_metadata") or data.get("metadata", {})
if "disable_global_guardrail" in metadata:
return metadata["disable_global_guardrail"]
if "disable_global_guardrails" in metadata:
return metadata["disable_global_guardrails"]
return False
def _is_valid_response_type(self, result: Any) -> bool:

View file

@ -197,7 +197,7 @@ class TestCustomGuardrailShouldRunGuardrail:
data_with_disable_root = {
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "test"}],
"disable_global_guardrail": True,
"disable_global_guardrails": True,
}
result = custom_guardrail.should_run_guardrail(
data=data_with_disable_root, event_type=GuardrailEventHooks.pre_call
@ -210,7 +210,7 @@ class TestCustomGuardrailShouldRunGuardrail:
data_with_disable_litellm = {
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "test"}],
"litellm_metadata": {"disable_global_guardrail": True},
"litellm_metadata": {"disable_global_guardrails": True},
}
result = custom_guardrail.should_run_guardrail(
data=data_with_disable_litellm, event_type=GuardrailEventHooks.pre_call
@ -223,7 +223,7 @@ class TestCustomGuardrailShouldRunGuardrail:
data_with_disable_metadata = {
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "test"}],
"metadata": {"disable_global_guardrail": True},
"metadata": {"disable_global_guardrails": True},
}
result = custom_guardrail.should_run_guardrail(
data=data_with_disable_metadata, event_type=GuardrailEventHooks.pre_call
@ -236,7 +236,7 @@ class TestCustomGuardrailShouldRunGuardrail:
data_with_disable_false = {
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "test"}],
"disable_global_guardrail": False,
"disable_global_guardrails": False,
}
result = custom_guardrail.should_run_guardrail(
data=data_with_disable_false, event_type=GuardrailEventHooks.pre_call

View file

@ -2263,7 +2263,7 @@ class TestPanwAirsMcpForceRun:
"test_panw_airs",
False,
"pre_call",
_simple_data(disable_global_guardrail=True),
_simple_data(disable_global_guardrails=True),
GuardrailEventHooks.pre_mcp_call,
False,
id="honors_disable_global_on_mcp_hooks",