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: keep fastapi import within proxy
Devin AI2876ac03ceaa
diff --git a/litellm/integrations/custom_guardrail.py b/litellm/integrations/custom_guardrail.pyindex ff07fa4a8ec..a6c32d78c00 100644--- a/litellm/integrations/custom_guardrail.py+++ b/litellm/integrations/custom_guardrail.py@@ -102,11 +102,9 @@ def is_guardrail_intervention(e: Exception) -> bool:),):return True- try:- from fastapi.exceptions import HTTPException- except ImportError:- return False- return isinstance(e, HTTPException) and e.status_code in _GUARDRAIL_BLOCK_STATUS_CODES+ from litellm.proxy.guardrails.exception_utils import is_fastapi_http_exception++ return is_fastapi_http_exception(e, _GUARDRAIL_BLOCK_STATUS_CODES)def _strict_guardrail_modes_enabled() -> bool:diff --git a/litellm/proxy/guardrails/exception_utils.py b/litellm/proxy/guardrails/exception_utils.pynew file mode 100644index 00000000000..47f2655fdaf--- /dev/null+++ b/litellm/proxy/guardrails/exception_utils.py@@ -0,0 +1,9 @@+from collections.abc import Collection+++def is_fastapi_http_exception(e: Exception, block_status_codes: Collection[int]) -> bool:+ try:+ from fastapi.exceptions import HTTPException+ except ImportError:+ return False+ return isinstance(e, HTTPException) and e.status_code in block_status_codes