Skip to content

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]

fix(guardrails): import ModelResponse lazily to avoid cyclic import alert

joshua-berric1d0d29d01db
diff --git a/litellm/integrations/custom_guardrail.py b/litellm/integrations/custom_guardrail.py
index 34b79e295e1..1d00ad8c29a 100644
--- a/litellm/integrations/custom_guardrail.py
+++ b/litellm/integrations/custom_guardrail.py
@@ -31,7 +31,6 @@ from litellm.types.utils import (
GuardrailStatus,
GuardrailTracingDetail,
LLMResponseTypes,
- ModelResponse,
StandardLoggingGuardrailInformation,
)
@@ -907,6 +906,8 @@ class CustomGuardrail(CustomLogger):
response: Final = (
kwargs.get("async_complete_streaming_response") or kwargs.get("complete_streaming_response") or result
)
+ from litellm.types.utils import ModelResponse
+
output_translation: Final = (
get_guardrail_translation_mapping(CallTypes.acompletion)()
if isinstance(response, ModelResponse)