Litellm ishaan april15#25813
Conversation
…rs and dedupes them in memory. Current fix includes - Updates test case - Optimized query with docstring. The change leverages deduplication and sorting logic from SQL - Added a bench script to differentiate peak memory usage before and after
…ull_type_handling bedrock api response null type handling
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
|
Greptile SummaryThis PR delivers two independent bug fixes: (1) a null-safety patch for Bedrock Guardrails, replacing Confidence Score: 5/5Safe to merge — all changes are well-tested and no P0/P1 issues were found. The bedrock null-safety fixes are guarded by the existing top-level try/except and covered by thorough new tests. The health-check query optimization is semantically equivalent to the old Python-side dedup, the single-statement CONCURRENTLY migration is correctly designed to run outside Prisma's transaction wrapping, and all remaining test modifications accurately reflect the new DB-side deduplication contract rather than weakening coverage. No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/proxy/utils.py | Replaces full-table-scan + Python-side deduplication with Prisma distinct=["model_id","model_name"] ORDER BY checked_at DESC, eliminating O(n) memory usage; logic is semantically equivalent. |
| litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py | Replaces .get("key", []) with .get("key") or [] throughout to handle explicit null values returned by the Bedrock API; function-level try/except ensures graceful degradation. |
| litellm-proxy-extras/litellm_proxy_extras/migrations/20260415120000_health_check_latest_per_model_index/migration.sql | Adds composite index on (model_id, model_name, checked_at DESC) using CREATE INDEX CONCURRENTLY; correctly kept as a single statement so Prisma runs it outside a transaction. |
| tests/test_litellm/proxy/guardrails/guardrail_hooks/test_bedrock_guardrails.py | Adds comprehensive null-safety test classes covering all policy sub-list fields, including BLOCKED-detection through mixed null/non-null fields; tests are well-structured and use mocks correctly. |
| tests/test_litellm/proxy/test_health_check_functions.py | Existing tests updated to reflect DB-side deduplication (mock now returns already-distinct rows); new test covers same model_name with and without model_id returning two distinct DB rows. |
| scripts/health_check/benchmark_get_all_latest_health_checks.py | New benchmark script for measuring memory and latency of get_all_latest_health_checks; inserts a runtime sys.path manipulation to import from the repo root which is acceptable for a standalone script. |
Sequence Diagram
sequenceDiagram
participant Caller
participant get_all_latest_health_checks
participant PostgreSQL
Note over get_all_latest_health_checks,PostgreSQL: NEW: DB-side deduplication
Caller->>get_all_latest_health_checks: await get_all_latest_health_checks()
get_all_latest_health_checks->>PostgreSQL: SELECT DISTINCT ON (model_id, model_name) *
FROM LiteLLM_HealthCheckTable
ORDER BY model_id, model_name, checked_at DESC
PostgreSQL-->>get_all_latest_health_checks: N distinct rows (one per model)
get_all_latest_health_checks-->>Caller: list of latest health checks
Note over get_all_latest_health_checks,PostgreSQL: OLD: full table scan + Python dedup
Caller->>get_all_latest_health_checks: await get_all_latest_health_checks()
get_all_latest_health_checks->>PostgreSQL: SELECT * FROM LiteLLM_HealthCheckTable ORDER BY checked_at DESC
PostgreSQL-->>get_all_latest_health_checks: ALL historical rows
get_all_latest_health_checks->>get_all_latest_health_checks: Python dedup loop (O(n) memory)
get_all_latest_health_checks-->>Caller: list of latest health checks
Reviews (2): Last reviewed commit: "fix(ci): sync uv.lock with pyproject.tom..." | Re-trigger Greptile
… creation. Index creation is scoped to a single statements and hence Validated index creation in local env
Optimize database query to prevent OOM errors during health checks
1013137
into
litellm_internal_staging
Relevant issues
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/test_litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
CI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Screenshots / Proof of Fix
Type
🆕 New Feature
🐛 Bug Fix
🧹 Refactoring
📖 Documentation
🚄 Infrastructure
✅ Test
Changes