fix: keep fastapi import within proxy

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Devin AI 2026-09-17 09:41:58 +00:00
parent 25949a87ac
commit 2876ac03ce
2 changed files with 12 additions and 5 deletions

View file

@ -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:

View file

@ -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