diff --git a/litellm/proxy/guardrails/guardrail_hooks/akto/akto.py b/litellm/proxy/guardrails/guardrail_hooks/akto/akto.py index 009be392221..ea92c589186 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/akto/akto.py +++ b/litellm/proxy/guardrails/guardrail_hooks/akto/akto.py @@ -280,14 +280,11 @@ class AktoGuardrail(CustomGuardrail): @staticmethod def handle_guardrail_response(response: httpx.Response) -> Tuple[bool, str]: - """Parse the Akto guardrail response. Returns (allowed, reason).""" - if response.status_code != 200: - verbose_proxy_logger.error("Akto returned HTTP %d", response.status_code) - raise httpx.HTTPStatusError( - f"Akto returned unexpected status {response.status_code}", - request=response.request, - response=response, - ) + """Parse the Akto guardrail response. Returns (allowed, reason). + + Note: Non-200 responses are already raised as httpx.HTTPStatusError + by AsyncHTTPHandler.post() before reaching this method. + """ try: result = response.json() except (json.JSONDecodeError, ValueError) as e: @@ -332,8 +329,9 @@ class AktoGuardrail(CustomGuardrail): except HTTPException: raise except (httpx.RequestError, httpx.HTTPStatusError) as e: + status = getattr(getattr(e, "response", None), "status_code", None) + verbose_proxy_logger.error("Akto error (status=%s): %s", status, e) if self.unreachable_fallback == "fail_open": - verbose_proxy_logger.critical("Akto unreachable (fail-open): %s", e) return inputs raise HTTPException( status_code=503, detail="Akto guardrail service unreachable" diff --git a/tests/guardrails_tests/test_akto_guardrails.py b/tests/guardrails_tests/test_akto_guardrails.py index 45d3d6ab266..4008097753a 100644 --- a/tests/guardrails_tests/test_akto_guardrails.py +++ b/tests/guardrails_tests/test_akto_guardrails.py @@ -248,13 +248,6 @@ def test_handle_guardrail_response_non_dict(): assert allowed is True -def test_handle_guardrail_response_error_status(): - mock_resp = MagicMock(spec=httpx.Response) - mock_resp.status_code = 500 - mock_resp.request = MagicMock() - with pytest.raises(httpx.HTTPStatusError): - AktoGuardrail.handle_guardrail_response(mock_resp) - def test_handle_guardrail_response_non_json_body(): mock_resp = MagicMock(spec=httpx.Response)