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]

addressing comments

yuneng-jiang39bf5b780b7b
diff --git a/litellm/proxy/guardrails/guardrail_endpoints.py b/litellm/proxy/guardrails/guardrail_endpoints.py
index c0c87842427..07702252a10 100644
--- a/litellm/proxy/guardrails/guardrail_endpoints.py
+++ b/litellm/proxy/guardrails/guardrail_endpoints.py
@@ -15,6 +15,7 @@ from litellm.proxy._types import UserAPIKeyAuth
from litellm.proxy.auth.user_api_key_auth import user_api_key_auth
from litellm.proxy.guardrails.guardrail_registry import GuardrailRegistry
from litellm.types.guardrails import (
+ BaseLitellmParams,
PII_ENTITY_CATEGORIES_MAP,
ApplyGuardrailRequest,
ApplyGuardrailResponse,
@@ -178,11 +179,16 @@ async def list_guardrails_v2():
unmasked_length=4,
number_of_asterisks=4,
)
+ masked_litellm_params = (
+ BaseLitellmParams(**masked_litellm_params_dict)
+ if masked_litellm_params_dict
+ else None
+ )
guardrail_configs.append(
GuardrailInfoResponse(
guardrail_id=guardrail.get("guardrail_id"),
guardrail_name=guardrail.get("guardrail_name"),
- litellm_params=masked_litellm_params_dict,
+ litellm_params=masked_litellm_params,
guardrail_info=guardrail.get("guardrail_info"),
created_at=guardrail.get("created_at"),
updated_at=guardrail.get("updated_at"),
@@ -196,19 +202,27 @@ async def list_guardrails_v2():
for guardrail in in_memory_guardrails:
# only add guardrails that are not in DB guardrail list already
if guardrail.get("guardrail_id") not in seen_guardrail_ids:
- in_memory_litellm_params = dict(
- guardrail.get("litellm_params") or {}
- )
+ in_memory_litellm_params_raw = guardrail.get("litellm_params")
+ in_memory_litellm_params_dict = (
+ in_memory_litellm_params_raw.model_dump(exclude_none=True)
+ if isinstance(in_memory_litellm_params_raw, LitellmParams)
+ else in_memory_litellm_params_raw
+ ) or {}
masked_in_memory_litellm_params = _get_masked_values(
- in_memory_litellm_params,
+ in_memory_litellm_params_dict,
unmasked_length=4,
number_of_asterisks=4,
)
+ masked_in_memory_litellm_params_typed = (
+ BaseLitellmParams(**masked_in_memory_litellm_params)
+ if masked_in_memory_litellm_params
+ else None
+ )
guardrail_configs.append(
GuardrailInfoResponse(
guardrail_id=guardrail.get("guardrail_id"),
guardrail_name=guardrail.get("guardrail_name"),
- litellm_params=masked_in_memory_litellm_params,
+ litellm_params=masked_in_memory_litellm_params_typed,
guardrail_info=dict(guardrail.get("guardrail_info") or {}),
guardrail_definition_location="config",
)
@@ -688,11 +702,16 @@ async def get_guardrail_info(guardrail_id: str):
unmasked_length=4,
number_of_asterisks=4,
)
+ masked_litellm_params = (
+ BaseLitellmParams(**masked_litellm_params_dict)
+ if masked_litellm_params_dict
+ else None
+ )
return GuardrailInfoResponse(
guardrail_id=result.get("guardrail_id"),
guardrail_name=result.get("guardrail_name"),
- litellm_params=masked_litellm_params_dict,
+ litellm_params=masked_litellm_params,
guardrail_info=dict(result.get("guardrail_info") or {}),
created_at=result.get("created_at"),
updated_at=result.get("updated_at"),