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)