From d9c761d31bea5d7abcc315ca3a0affbf89994129 Mon Sep 17 00:00:00 2001 From: rzeta-10 Date: Tue, 24 Mar 2026 01:39:31 +0530 Subject: [PATCH] enhance AktoGuardrail error handling and update test initialization comments --- litellm/proxy/guardrails/guardrail_hooks/akto/__init__.py | 1 + litellm/proxy/guardrails/guardrail_hooks/akto/akto.py | 3 ++- tests/guardrails_tests/test_akto_guardrails.py | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/litellm/proxy/guardrails/guardrail_hooks/akto/__init__.py b/litellm/proxy/guardrails/guardrail_hooks/akto/__init__.py index 2a90fb3b37f..77795baa83a 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/akto/__init__.py +++ b/litellm/proxy/guardrails/guardrail_hooks/akto/__init__.py @@ -12,6 +12,7 @@ if TYPE_CHECKING: def initialize_guardrail(litellm_params: "LitellmParams", guardrail: "Guardrail"): import litellm + # Note: AktoGuardrail only supports pre_call. _akto_callback = AktoGuardrail( akto_base_url=getattr(litellm_params, "akto_base_url", None), akto_api_key=getattr(litellm_params, "akto_api_key", None), diff --git a/litellm/proxy/guardrails/guardrail_hooks/akto/akto.py b/litellm/proxy/guardrails/guardrail_hooks/akto/akto.py index eae23ef097f..34afcd23582 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/akto/akto.py +++ b/litellm/proxy/guardrails/guardrail_hooks/akto/akto.py @@ -114,7 +114,8 @@ class AktoGuardrail(CustomGuardrail): }, timeout=self.guardrail_timeout, ) - except Exception as e: + except (httpx.RequestError, httpx.HTTPStatusError) as e: + # Fire-and-forget: log but never crash the request path verbose_proxy_logger.error("Akto blocked-request ingest error: %s", e) # ── Payload builders ── diff --git a/tests/guardrails_tests/test_akto_guardrails.py b/tests/guardrails_tests/test_akto_guardrails.py index 433bd29efa1..2bb8801e36d 100644 --- a/tests/guardrails_tests/test_akto_guardrails.py +++ b/tests/guardrails_tests/test_akto_guardrails.py @@ -135,6 +135,7 @@ def test_init_from_env(): def test_init_defaults(): + # patch.dict restores popped keys on exit with patch.dict(os.environ, {}, clear=False): os.environ.pop("AKTO_ACCOUNT_ID", None) os.environ.pop("AKTO_VXLAN_ID", None)