Skip to content

Litellm ishaan april15#25813

Merged
ishaan-berri merged 10 commits intolitellm_internal_stagingfrom
litellm_ishaan_april15
Apr 16, 2026
Merged

Litellm ishaan april15#25813
ishaan-berri merged 10 commits intolitellm_internal_stagingfrom
litellm_ishaan_april15

Conversation

@ishaan-berri
Copy link
Copy Markdown
Contributor

Relevant issues

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/test_litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

Delays 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)

CI status guideline:

  • 50-55 passing tests: main is stable with minor issues.
  • 45-49 passing tests: acceptable but needs attention
  • <= 40 passing tests: unstable; be careful with your merges and assess the risk.
  • 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

kothamah and others added 7 commits March 19, 2026 13:52
…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
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Apr 16, 2026 1:17am

Request Review

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 15, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 3 committers have signed the CLA.

✅ kothamah
❌ ishaan-berri
❌ harish876
You have signed the CLA already but the status is still pending? Let us recheck it.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 15, 2026

Greptile Summary

This PR delivers two independent bug fixes: (1) a null-safety patch for Bedrock Guardrails, replacing .get("key", []) with .get("key") or [] at every list-field access to handle the Bedrock API returning explicit JSON null (which .get("key", []) does not guard against), and (2) a performance optimization for get_all_latest_health_checks that replaces a full-table Python-side dedup with a DB-level DISTINCT ON (model_id, model_name) ORDER BY checked_at DESC, backed by a new composite index added via a single-statement CREATE INDEX CONCURRENTLY migration (correctly kept single-statement so Prisma runs it outside a transaction).

Confidence Score: 5/5

Safe 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.

Important Files Changed

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
Loading

Reviews (2): Last reviewed commit: "fix(ci): sync uv.lock with pyproject.tom..." | Re-trigger Greptile

harish876 and others added 2 commits April 15, 2026 22:52
… 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
@ishaan-berri ishaan-berri merged commit 1013137 into litellm_internal_staging Apr 16, 2026
97 of 100 checks passed
@ishaan-berri ishaan-berri deleted the litellm_ishaan_april15 branch April 16, 2026 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants