Fix #4498: Strip File objects from messages when multimodal is unsupported#4499
Open
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Open
Fix #4498: Strip File objects from messages when multimodal is unsupported#4499devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Conversation
Fixes #4498. When returns False, previously returned early without removing the key from messages. This left non-serializable File objects in the payload, causing TypeError during JSON serialization by httpx. Now the key is always stripped from every message, with a warning logged when files are dropped because the model lacks multimodal support or crewai-files is not installed. Co-Authored-By: João <joao@crewai.com>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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.
Fix #4498: Strip File objects from messages when multimodal is unsupported
Summary
When
input_filescontainingFileobjects are passed to a model that doesn't support multimodal (e.g., gemma3 via Ollama),_process_message_filesreturned early without removing thefileskey from message dicts. These non-serializableFileobjects then leaked into the API payload, causingTypeError: Object of type File is not JSON serializablefrom httpx.The fix ensures the
fileskey is always stripped from every message, regardless of multimodal support. A warning is logged when files are dropped. The same fix is applied to three code paths:BaseLLM._process_message_files(sync — native providers)LLM._process_message_files(sync — LiteLLM wrapper)LLM._aprocess_message_files(async — LiteLLM wrapper)8 regression tests added covering BaseLLM, LiteLLM sync/async, OpenAI native, JSON serializability, multiple messages, and warning logging.
Review & Testing Checklist for Human
input_fileswith an image to a vision model (e.g.,gpt-4o) and confirm files are correctly converted to content blocks (not dropped). The tests only cover the unsupported path directly."dropped from the request") won't be excessively noisy for users who pass many messages with files to non-multimodal models. Consider if it should log once instead.provider/apivariable lookups moved inside the loop body — functionally equivalent but only evaluated for messages that actually have files.Notes