Skip to content

Commit 268b984

Browse files
committed
added test for updating in memory guardrails
1 parent 66202d0 commit 268b984

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/test_litellm/proxy/guardrails/test_guardrail_registry.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
from litellm.integrations.custom_guardrail import CustomGuardrail
12
from litellm.proxy.guardrails.guardrail_registry import (
23
get_guardrail_initializer_from_hooks,
4+
InMemoryGuardrailHandler,
35
)
6+
from litellm.types.guardrails import GuardrailEventHooks, Guardrail, LitellmParams
47

58

69
def test_get_guardrail_initializer_from_hooks():
@@ -15,3 +18,33 @@ def test_guardrail_class_registry():
1518
print(f"guardrail_class_registry: {guardrail_class_registry}")
1619
assert "aim" in guardrail_class_registry
1720
assert "aporia" in guardrail_class_registry
21+
22+
23+
def test_update_in_memory_guardrail():
24+
handler = InMemoryGuardrailHandler()
25+
handler.guardrail_id_to_custom_guardrail["123"] = CustomGuardrail(
26+
guardrail_name="test-guardrail",
27+
default_on=False,
28+
event_hook=GuardrailEventHooks.pre_call,
29+
)
30+
31+
handler.update_in_memory_guardrail(
32+
"123",
33+
Guardrail(
34+
guardrail_name="test-guardrail",
35+
litellm_params=LitellmParams(
36+
guardrail="test-guardrail", mode="pre_call", default_on=True
37+
),
38+
),
39+
)
40+
41+
assert (
42+
handler.guardrail_id_to_custom_guardrail["123"].should_run_guardrail(
43+
data={}, event_type=GuardrailEventHooks.pre_call
44+
)
45+
is True
46+
)
47+
assert (
48+
handler.guardrail_id_to_custom_guardrail["123"].event_hook
49+
is GuardrailEventHooks.pre_call
50+
)

0 commit comments

Comments
 (0)