Merge pull request #21975 from BerriAI/litellm_cicd_24_02

Fix content filter tests
This commit is contained in:
Sameer Kankute 2026-02-24 09:40:27 +05:30 committed by GitHub
commit 1696c094bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -214,7 +214,7 @@ class ContentFilterGuardrail(CustomGuardrail):
self.category_keywords: Dict[str, Tuple[str, str, ContentFilterAction]] = (
{}
) # keyword -> (category, severity, action)
# Always-block keywords are checked before exceptions (cannot be bypassed)
# Always-block keywords are checked after exceptions (exceptions take precedence)
self.always_block_category_keywords: Dict[
str, Tuple[str, str, ContentFilterAction]
] = {}
@ -1068,7 +1068,15 @@ class ContentFilterGuardrail(CustomGuardrail):
"""
text_lower = text.lower()
# Always-block keywords are matched first — exceptions do not apply to them.
# Check exceptions first — they take precedence over always-block keywords too.
for exception in exceptions:
if exception in text_lower:
verbose_proxy_logger.debug(
f"Exception phrase '{exception}' found, skipping category keyword check"
)
return None
# Always-block keywords are checked after exceptions.
for keyword, (category, severity, action) in self.always_block_category_keywords.items():
keyword_pattern_str = self._keyword_to_regex_pattern(keyword)
if " " in keyword:
@ -1082,14 +1090,6 @@ class ContentFilterGuardrail(CustomGuardrail):
)
return (keyword, category, severity, action)
# First check if any exception applies
for exception in exceptions:
if exception in text_lower:
verbose_proxy_logger.debug(
f"Exception phrase '{exception}' found, skipping category keyword check"
)
return None
# Check category keywords
for keyword, (category, severity, action) in self.category_keywords.items():
# Convert asterisks (*) in keywords to regex wildcards