The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
added test for updating in memory guardrails
=268b984cb65f
diff --git a/tests/test_litellm/proxy/guardrails/test_guardrail_registry.py b/tests/test_litellm/proxy/guardrails/test_guardrail_registry.pyindex f05ec653fbd..23432b18ca0 100644--- a/tests/test_litellm/proxy/guardrails/test_guardrail_registry.py+++ b/tests/test_litellm/proxy/guardrails/test_guardrail_registry.py@@ -1,6 +1,9 @@+from litellm.integrations.custom_guardrail import CustomGuardrailfrom litellm.proxy.guardrails.guardrail_registry import (get_guardrail_initializer_from_hooks,+ InMemoryGuardrailHandler,)+from litellm.types.guardrails import GuardrailEventHooks, Guardrail, LitellmParamsdef test_get_guardrail_initializer_from_hooks():@@ -15,3 +18,33 @@ def test_guardrail_class_registry():print(f"guardrail_class_registry: {guardrail_class_registry}")assert "aim" in guardrail_class_registryassert "aporia" in guardrail_class_registry+++def test_update_in_memory_guardrail():+ handler = InMemoryGuardrailHandler()+ handler.guardrail_id_to_custom_guardrail["123"] = CustomGuardrail(+ guardrail_name="test-guardrail",+ default_on=False,+ event_hook=GuardrailEventHooks.pre_call,+ )++ handler.update_in_memory_guardrail(+ "123",+ Guardrail(+ guardrail_name="test-guardrail",+ litellm_params=LitellmParams(+ guardrail="test-guardrail", mode="pre_call", default_on=True+ ),+ ),+ )++ assert (+ handler.guardrail_id_to_custom_guardrail["123"].should_run_guardrail(+ data={}, event_type=GuardrailEventHooks.pre_call+ )+ is True+ )+ assert (+ handler.guardrail_id_to_custom_guardrail["123"].event_hook+ is GuardrailEventHooks.pre_call+ )