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
fix: respect pangea guardrail default_on during initialization
Yuta Saitocef087f88b96
diff --git a/litellm/proxy/guardrails/guardrail_hooks/pangea/__init__.py b/litellm/proxy/guardrails/guardrail_hooks/pangea/__init__.pyindex 181633065e4..210d9ac7879 100644--- a/litellm/proxy/guardrails/guardrail_hooks/pangea/__init__.py+++ b/litellm/proxy/guardrails/guardrail_hooks/pangea/__init__.py@@ -21,6 +21,7 @@ def initialize_guardrail(litellm_params: "LitellmParams", guardrail: "Guardrail"pangea_output_recipe=litellm_params.pangea_output_recipe,api_base=litellm_params.api_base,api_key=litellm_params.api_key,+ event_hook=litellm_params.mode,default_on=litellm_params.default_on,)litellm.logging_callback_manager.add_litellm_callback(_pangea_callback)diff --git a/litellm/proxy/guardrails/guardrail_hooks/pangea/pangea.py b/litellm/proxy/guardrails/guardrail_hooks/pangea/pangea.pyindex 619323e9073..ca3e6a90801 100644--- a/litellm/proxy/guardrails/guardrail_hooks/pangea/pangea.py+++ b/litellm/proxy/guardrails/guardrail_hooks/pangea/pangea.py@@ -95,8 +95,17 @@ class PangeaHandler(CustomGuardrail):self.pangea_input_recipe = pangea_input_recipeself.pangea_output_recipe = pangea_output_recipe+ supported_event_hooks = [+ GuardrailEventHooks.pre_call,+ GuardrailEventHooks.post_call,+ ]+# Pass relevant kwargs to the parent class- super().__init__(guardrail_name=guardrail_name, **kwargs)+ super().__init__(+ guardrail_name=guardrail_name,+ supported_event_hooks=supported_event_hooks,+ **kwargs+ )verbose_proxy_logger.debug(f"Initialized Pangea Guardrail: name={guardrail_name}, recipe={pangea_input_recipe}, api_base={self.api_base}")diff --git a/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_pangea.py b/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_pangea.pyindex 9d5d6fd54c4..d770efee1c9 100644--- a/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_pangea.py+++ b/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_pangea.py@@ -4,11 +4,13 @@ import httpximport pytestfrom fastapi import HTTPException+from litellm.proxy.guardrails.guardrail_hooks.pangea import initialize_guardrailfrom litellm.proxy.guardrails.guardrail_hooks.pangea.pangea import (PangeaGuardrailMissingSecrets,PangeaHandler,)from litellm.proxy.guardrails.init_guardrails import init_guardrails_v2+from litellm.types.guardrails import GuardrailEventHooks, LitellmParamsfrom litellm.types.utils import Choices, Message, ModelResponse@@ -44,6 +46,28 @@ def test_pangea_guardrail_config():)+def test_initialize_guardrail_sets_event_hook():+ litellm_params = LitellmParams(+ guardrail="pangea",+ mode=GuardrailEventHooks.post_call,+ api_key="pts_pangeatokenid",+ pangea_input_recipe="guard_llm_request",+ pangea_output_recipe="guard_llm_response",+ )++ guardrail = {"guardrail_name": "pangea-ai-guard"}++ with patch(+ "litellm.logging_callback_manager.add_litellm_callback"+ ) as mock_add_callback:+ callback = initialize_guardrail(+ litellm_params=litellm_params, guardrail=guardrail+ )++ assert callback.event_hook == GuardrailEventHooks.post_call+ mock_add_callback.assert_called_once_with(callback)++def test_pangea_guardrail_config_no_api_key():with pytest.raises(PangeaGuardrailMissingSecrets):init_guardrails_v2(