You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
LitellmModel drops an explicitly-configured empty extra_query / metadata dict before calling litellm.acompletion, because it uses falsy checks (if model_settings.extra_query:) instead of is not None checks. This diverges from the other two model paths:
OpenAI (openai_chatcompletions.py): passes extra_query through as-is and forwards metadata unless it is None (_non_null_or_omit).
Use is not None checks for extra_query and metadata in the LiteLLM chat path, matching #4544's handling in the AnyLLM path. Empty dicts are now forwarded instead of silently discarded.
Verification
Added a regression test (test_empty_extra_query_and_metadata_are_forwarded) that mocks litellm.acompletion and asserts extra_query={} and metadata={} reach the provider. Confirmed it fails (KeyError: 'extra_query') before the fix and passes after.
ruff check / ruff format --check clean on both touched files.
Related LiteLLM tests pass (test_litellm_extra_body.py, test_litellm_content_filter.py, test_litellm_usage_requests.py — 16 passed).
Thanks for the contribution. I confirmed that LitellmModel currently omits empty extra_query and metadata mappings, but I could not find a supported behavior that changes when those empty mappings are passed to litellm.acompletion. ModelSettings resolution already accepts {} as an explicit override, so it can clear inherited values; after that, omitting the empty mapping produces the same request outcome. The new test only locks the adapter-to-LiteLLM call shape, while #4544's empty-mapping assertions were incidental to its extra_body fix and do not establish a separate need here.
I am going to close this PR. If there is a concrete LiteLLM provider or supported callback for which omission and {} produce different user-visible behavior, please share that scenario and we can reconsider the narrower requirement.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LitellmModeldrops an explicitly-configured emptyextra_query/metadatadict before callinglitellm.acompletion, because it uses falsy checks (if model_settings.extra_query:) instead ofis not Nonechecks. This diverges from the other two model paths:openai_chatcompletions.py): passesextra_querythrough as-is and forwardsmetadataunless it isNone(_non_null_or_omit).any_llm_model.py): switched tois not Nonechecks in fix(extensions): nest extra_body on the any-llm chat path #4544.litellm_model.py): still drops{}.Change
Use
is not Nonechecks forextra_queryandmetadatain the LiteLLM chat path, matching #4544's handling in the AnyLLM path. Empty dicts are now forwarded instead of silently discarded.Verification
test_empty_extra_query_and_metadata_are_forwarded) that mockslitellm.acompletionand assertsextra_query={}andmetadata={}reach the provider. Confirmed it fails (KeyError: 'extra_query') before the fix and passes after.ruff check/ruff format --checkclean on both touched files.test_litellm_extra_body.py,test_litellm_content_filter.py,test_litellm_usage_requests.py— 16 passed).