Skip to content

fix(litellm): log and back off on non-filter BadRequestError - #1472

Open
pcbeingused333 wants to merge 1 commit into
huggingface:mainfrom
pcbeingused333:c0550-litellm-badrequest
Open

pcbeingused333 wants to merge 1 commit into
huggingface:mainfrom
pcbeingused333:c0550-litellm-badrequest

Conversation

@pcbeingused333

Copy link
Copy Markdown

Fix silently swallowed BadRequestError in the LiteLLM endpoint retry loop.

The LiteLLMClient retry loop had a dedicated except litellm.BadRequestError branch that only acted when the message was the Azure content-filter one. Any other BadRequestError (for example an unsupported parameter) was swallowed: no log, no backoff, and because the later except Exception is a sibling clause it never ran. Each prompt therefore hit the API api_max_retry times back to back and ended with an empty LitellmModelResponse, with nothing in the logs about the cause.

The fix folds the content-filter check into the generic handler, so the filter case still returns an empty response immediately and every other error is logged and backed off like any other API failure.

Tests: tests/unit/models/endpoints/test_litellm_model.py mocks litellm.completion and checks that a non-filter BadRequestError is logged and backed off for every attempt, and that the content-filter case still returns after a single call.


This pull request was prepared with the assistance of an AI coding agent (Claude Code) and submitted by Alex Castillo, who is responsible for its content.

The BadRequestError handler only acted on the Azure content-filter
message; any other BadRequestError (e.g. an unsupported parameter) was
swallowed silently with no log and no backoff, so each prompt hammered
the API max_retry times and ended with an empty response and no trace
of the cause. Route those errors through the generic handler so they
are logged and backed off like every other API failure.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.

1 participant