mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-04 02:31:27 +00:00
fix(guardrails): never map empty guardrail names onto a sibling id
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
586d51f15e
commit
937179bde1
2 changed files with 5 additions and 4 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue