Repository navigation
fix(litellm): handle image_url given as a plain string - #4479
Open
1AbdullahButt wants to merge 1 commit into
Open
1AbdullahButt wants to merge 1 commit into
1AbdullahButt wants to merge 1 commit into
Conversation
LiteLLM types image_url as Union[str, ChatCompletionImageUrlObject], but _get_attributes_from_image called dict(image), which raises ValueError on a string. The error aborted the whole completion request extractor, so the span lost the remaining input messages, input.value, invocation parameters and tools. Record the string as the image URL instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
fixes #4478
The LiteLLM instrumentor drops most request attributes when a message has an
image_urlpart given as a plain URL string.Problem
LiteLLM accepts
image_urlas either{"url": "..."}or the URL string itself (ChatCompletionImageObject.image_url: Union[str, ChatCompletionImageUrlObject]inlitellm/types/llms/openai.py)._get_attributes_from_imagecallsdict(image), which raises on a string:_suppress_extractor_errorscatches it, so the call still works. But_instrument_func_type_completionstops at that point, and the span is left without the rest of the input messages,input.value,llm.invocation_parameters, andllm.tools.Repro:
The openai instrumentor had the same bug (#2188) and fixed it in #2213. This PR makes the same change in the LiteLLM instrumentor.
Fix
_get_attributes_from_imagenow treats a string as the URL and readsurlfrom a mapping with.get(). A mapping withouturlis now skipped instead of raisingKeyError.Tests
Added
test_completion_image_url_as_string. It checks the image URL,input.value, and invocation parameters on the span.ruff formatandruff checkpass on the changed files.I made this change with help from Claude Code, and I reviewed the diff and the test results myself.
🤖 Generated with Claude Code