mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-11 22:51:28 +00:00
Merge pull request #21975 from BerriAI/litellm_cicd_24_02
Fix content filter tests
This commit is contained in:
commit
1696c094bc
1 changed files with 10 additions and 10 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue