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]

refactor(guardrails): generalize _to_dict to any pydantic model

Yuneng Jiang8b31b200ca03
diff --git a/litellm/proxy/guardrails/usage_endpoints.py b/litellm/proxy/guardrails/usage_endpoints.py
index c63526e4833..f56b22ddd49 100644
--- a/litellm/proxy/guardrails/usage_endpoints.py
+++ b/litellm/proxy/guardrails/usage_endpoints.py
@@ -20,7 +20,6 @@ from litellm.repositories.table_repositories import (
SpendLogGuardrailIndexRepository,
SpendLogsRepository,
)
-from litellm.types.guardrails import LitellmParams
router = APIRouter()
@@ -146,8 +145,8 @@ def _get_guardrail_field(g: Any, field: str) -> Any:
def _to_dict(value: Any) -> Dict[str, Any]:
- """Coerce a LitellmParams / guardrail_info value into a plain dict."""
- if isinstance(value, LitellmParams):
+ """Coerce a pydantic model (e.g. LitellmParams) / dict value into a plain dict."""
+ if isinstance(value, BaseModel):
return value.model_dump(exclude_none=True)
if isinstance(value, dict):
return value