Skip to content

fix(models): avoid AttributeError on LiteLLM_ProxyModelTable revalidation - #37808

Open
wuying8 wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
wuying8:litellm_fix_model_block_response_serialization
Open

fix(models): avoid AttributeError on LiteLLM_ProxyModelTable revalidation#37808
wuying8 wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
wuying8:litellm_fix_model_block_response_serialization

Conversation

@wuying8

@wuying8 wuying8 commented Aug 21, 2026

Copy link
Copy Markdown

TLDR

Problem this solves:

  • POST /model/block and POST /model/unblock fail with HTTP 500 AttributeError during Pydantic response validation

How it solves it:

  • Return non-dict inputs unchanged in LiteLLM_ProxyModelTable.check_potential_json_str before accessing dict keys

Relevant issues

Linear ticket

Pre-Submission checklist

  • I have added meaningful tests
  • My PR passes all CI/CD checks
  • My PR's scope is as isolated as possible

Proof of Fix

Before fix:
POST /model/block -> HTTP 500 (AttributeError: 'LiteLLM_ProxyModelTable' object has no attribute 'get')

After fix:
POST /model/block -> HTTP 200 OK with model details payload

Type

🐛 Bug Fix

Changes

  • litellm/models/model.py: Type-guard values in check_potential_json_str validator to handle LiteLLM_ProxyModelTable instances during response revalidation.
  • tests/test_litellm/models/test_models.py: Add regression test for model_validate on an existing LiteLLM_ProxyModelTable instance.

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

@CLAassistant

CLAassistant commented Aug 21, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@greptile-apps

greptile-apps Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR prevents LiteLLM_ProxyModelTable revalidation from treating an existing model instance as a dictionary.

  • Adds a type guard before dictionary-specific JSON-field normalization.
  • Adds a regression test covering model_validate with an existing model instance.

Confidence Score: 5/5

The PR appears safe to merge, with no actionable regressions identified.

The validator now safely preserves non-dictionary inputs while retaining the existing parsing behavior for dictionary construction paths, and the regression test covers the reported model-instance revalidation case.

Important Files Changed

Filename Overview
litellm/models/model.py Adds a narrow input-shape guard while preserving JSON-string normalization for dictionary inputs.
tests/test_litellm/models/test_models.py Adds focused regression coverage confirming that an existing proxy model instance can be revalidated without losing field values.

Reviews (1): Last reviewed commit: "fix(models): avoid AttributeError on Lit..." | Re-trigger Greptile

@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/models/model.py 50.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@wuying8
wuying8 force-pushed the litellm_fix_model_block_response_serialization branch from efcfcca to f343c3f Compare August 21, 2026 09:50
@codspeed-hq

codspeed-hq Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing wuying8:litellm_fix_model_block_response_serialization (f343c3f) with litellm_internal_staging (ff02d5c)

Open in CodSpeed

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.

2 participants