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(guardrails): never map empty guardrail names onto a sibling id
yucheng937179bde169
diff --git a/litellm/proxy/guardrails/usage_tracking.py b/litellm/proxy/guardrails/usage_tracking.pyindex b2ba6ec9ec5..7e11b69108b 100644--- a/litellm/proxy/guardrails/usage_tracking.py+++ b/litellm/proxy/guardrails/usage_tracking.py@@ -370,7 +370,7 @@ async def process_spend_logs_guardrail_usage({e["guardrail_name"]: e["guardrail_id"]for e in entries- if e.get("guardrail_id") and isinstance(e.get("guardrail_name"), str)+ if e.get("guardrail_id") and isinstance(e.get("guardrail_name"), str) and e["guardrail_name"]})for entry in entries:diff --git a/tests/test_litellm/proxy/guardrails/test_usage_tracking.py b/tests/test_litellm/proxy/guardrails/test_usage_tracking.pyindex 56a8bf2f0b0..13a53efcb27 100644--- a/tests/test_litellm/proxy/guardrails/test_usage_tracking.py+++ b/tests/test_litellm/proxy/guardrails/test_usage_tracking.py@@ -412,8 +412,9 @@ async def test_malformed_not_run_entry_does_not_drop_the_batch():payload["metadata"] = json.dumps({"guardrail_information": [- {"guardrail_name": ["not", "a", "string"], "guardrail_status": "not_run"},- {"guardrail_name": "cf", "guardrail_id": "cf-uuid", "guardrail_status": "success"},+ {"guardrail_name": ["not", "a", "string"], "guardrail_status": "success"},+ {"guardrail_name": "", "guardrail_id": "cf-uuid", "guardrail_status": "success"},+ {"guardrail_status": "not_run"},]})@@ -423,7 +424,7 @@ async def test_malformed_not_run_entry_does_not_drop_the_batch():index_rows = prisma.db.litellm_spendlogguardrailindex.create_many.call_args.kwargs["data"]assert [row["guardrail_id"] for row in index_rows] == ["cf-uuid"]metrics_create = prisma.db.litellm_dailyguardrailmetrics.upsert.call_args.kwargs["data"]["create"]- assert metrics_create["requests_evaluated"] == 1+ assert (metrics_create["guardrail_id"], metrics_create["requests_evaluated"]) == ("cf-uuid", 1)@pytest.mark.asyncio