test(guardrails): make callback cleanup defensive

Signed-off-by: xrwang8 <xrwang8@gmail.com>
This commit is contained in:
xrwang8 2026-09-16 16:59:59 +08:00
parent 9187ed52ce
commit 1b3cec0f53

View file

@ -115,7 +115,8 @@ class TestContentFilterGuardrail:
assert result["texts"] == ["Call <<PHONE_NUMBER>> about <<KEYWORD>>"]
finally:
litellm.callbacks.remove(guardrail)
if guardrail in litellm.callbacks:
litellm.callbacks.remove(guardrail)
def test_check_patterns_ssn(self):
"""