fix: raise ValueError when MIME type cannot be determined for file_uri#5220
fix: raise ValueError when MIME type cannot be determined for file_uri#5220giulio-leone wants to merge 2 commits intogoogle:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
Response from ADK Triaging Agent Hello @giulio-leone, thank you for creating this PR! It looks like you haven't signed the Contributor License Agreement (CLA) yet. Please visit https://cla.developers.google.com/ to sign it. Once you've done that, the "cla/google" check should pass. Thanks! |
When file_data.file_uri has no explicit MIME type and no recognizable extension, _get_content() previously fell back silently to application/octet-stream via _DEFAULT_MIME_TYPE. This broke providers that validate MIME types (e.g. Vertex AI for GCS URIs) without warning. Changes: - Raise ValueError with actionable guidance when MIME type cannot be determined and a file block would be constructed. Provider-specific text fallback paths (anthropic, vertex_ai non-gemini, etc.) still work without requiring MIME. - Propagate model= in the recursive _content_to_message_param() call for mixed function_response + file content, fixing incorrect provider detection on Vertex AI / Gemini. Fixes: google#5184
f8bee41 to
2f0d88b
Compare
|
Hi @giulio-leone , Thank you for your contribution! We appreciate you taking the time to submit this pull request. |
Summary
Fixes #5184
When
file_data.file_urihas no explicit MIME type and no recognizable extension, the LiteLLM integration previously fell back silently toapplication/octet-streamvia_DEFAULT_MIME_TYPE. This broke providers that validate MIME types (e.g. Vertex AI for GCS URIs) without any warning.Changes
1. Raise
ValueErrorinstead of silent fallback (_get_content)_DEFAULT_MIME_TYPEfallback assignment when MIME type cannot be determined.ValueErrorwith actionable guidance is now raised only when a file block would actually be constructed (i.e. the provider requires it).2. Propagate
model=in recursive_content_to_message_param()callfunction_response+ file content now forwardsmodel=model, fixing incorrect provider detection (e.g. Vertex AI Gemini vs non-Gemini).Tests
test_content_to_message_param_user_message_file_uri_without_mime_type→ expectsValueErrortest_get_content_file_uri_default_mime_type→ expectsValueErrortest_get_content_file_uri_no_mime_text_fallback_still_works— verifies text fallback works without MIMEtest_content_to_message_param_recursive_model_propagation— verifies model forwarding keeps file blocks for vertex_ai/geminitest_content_to_message_param_recursive_model_propagation_fallback— verifies text fallback for vertex_ai non-geminiAll 248 tests pass (3 new, 2 updated).