Skip to content

fix: raise ValueError when MIME type cannot be determined for file_uri#5220

Open
giulio-leone wants to merge 1 commit intogoogle:mainfrom
giulio-leone:fix/5184-litellm-mime-type-error
Open

fix: raise ValueError when MIME type cannot be determined for file_uri#5220
giulio-leone wants to merge 1 commit intogoogle:mainfrom
giulio-leone:fix/5184-litellm-mime-type-error

Conversation

@giulio-leone
Copy link
Copy Markdown

Summary

Fixes #5184

When file_data.file_uri has no explicit MIME type and no recognizable extension, the LiteLLM integration 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 any warning.

Changes

1. Raise ValueError instead of silent fallback (_get_content)

  • Removed the _DEFAULT_MIME_TYPE fallback assignment when MIME type cannot be determined.
  • A ValueError with actionable guidance is now raised only when a file block would actually be constructed (i.e. the provider requires it).
  • Provider-specific text fallback paths (anthropic, vertex_ai non-gemini, openai/azure non-file-id URIs) continue to work without requiring MIME type — they never construct a file block.

2. Propagate model= in recursive _content_to_message_param() call

  • The recursive call for mixed function_response + file content now forwards model=model, fixing incorrect provider detection (e.g. Vertex AI Gemini vs non-Gemini).

Tests

  • Updated test_content_to_message_param_user_message_file_uri_without_mime_type → expects ValueError
  • Updated test_get_content_file_uri_default_mime_type → expects ValueError
  • Added test_get_content_file_uri_no_mime_text_fallback_still_works — verifies text fallback works without MIME
  • Added test_content_to_message_param_recursive_model_propagation — verifies model forwarding keeps file blocks for vertex_ai/gemini
  • Added test_content_to_message_param_recursive_model_propagation_fallback — verifies text fallback for vertex_ai non-gemini

All 248 tests pass (3 new, 2 updated).

@google-cla
Copy link
Copy Markdown

google-cla bot commented Apr 9, 2026

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.

@adk-bot
Copy link
Copy Markdown
Collaborator

adk-bot commented Apr 9, 2026

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!

@adk-bot adk-bot added the models [Component] Issues related to model support label Apr 9, 2026
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
@giulio-leone giulio-leone force-pushed the fix/5184-litellm-mime-type-error branch from f8bee41 to 2f0d88b Compare April 9, 2026 03:01
@rohityan rohityan self-assigned this Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

models [Component] Issues related to model support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LiteLLM silently uses application/octet-stream when file_uri MIME type cannot be determined

3 participants