Commit 42eceb3
fix: raise ValueError for unsupported MIME types in file_data URI path
Merge #5023
Fixes #5022
## Problem
When a `Part` with `file_data.file_uri` has no determinable MIME type, the library fell back to `application/octet-stream` via `_DEFAULT_MIME_TYPE`. This value then propagated to LiteLLM which raised a cryptic internal `ValueError` with no guidance for the user.
The same failure occurred when the caller explicitly set `mime_type = "application/octet-stream"` on the Part. Both cases reach the same failure point.
There was also an inconsistency between the two content paths:
- The `inline_data` path raises `ValueError` immediately for unsupported MIME types
- The `file_data` path silently used a fallback and failed later with a cryptic message
`GcsArtifactService` generates URIs like `gs://bucket/artifact/0` with no extension and no MIME type, making ADK's own artifact system the primary trigger for this fallback.
## Fix
Removes `_DEFAULT_MIME_TYPE` and raises `ValueError` early with an actionable message when the resolved MIME type is either unknown or `application/octet-stream`. This aligns the `file_data` path with the existing fail-fast behavior of the `inline_data` path.
The logic order is also corrected so providers that always produce a text fallback (anthropic, non-Gemini Vertex AI) and OpenAI/Azure HTTP media URLs are handled before the MIME type guard, keeping those paths unaffected.
## Changes
- `src/google/adk/models/lite_llm.py`: remove `_DEFAULT_MIME_TYPE`, restructure file_uri handling block, raise `ValueError` for missing or generic MIME types
- `tests/unittests/models/test_litellm.py`: update two existing tests to assert the new `ValueError`, add one new test covering explicit `application/octet-stream`
## Testing
```
pytest tests/unittests/models/test_litellm.py
241 passed, 5 errors (pre-existing, missing pytest-mock fixture)
```
Format verified with `pyink`. mypy error count unchanged from main (26).
Co-authored-by: George Weale <gweale@google.com>
COPYBARA_INTEGRATE_REVIEW=#5023 from Raman369AI:fix/file-uri-unknown-mime-type-error c7eb917
PiperOrigin-RevId: 9386796101 parent 3c7d65a commit 42eceb3
2 files changed
Lines changed: 87 additions & 61 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
330 | 330 | | |
331 | 331 | | |
332 | 332 | | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | 333 | | |
338 | 334 | | |
339 | 335 | | |
| |||
1217 | 1213 | | |
1218 | 1214 | | |
1219 | 1215 | | |
1220 | | - | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
1221 | 1221 | | |
1222 | 1222 | | |
1223 | 1223 | | |
1224 | 1224 | | |
1225 | 1225 | | |
1226 | 1226 | | |
1227 | | - | |
1228 | | - | |
1229 | | - | |
1230 | | - | |
1231 | | - | |
1232 | | - | |
1233 | | - | |
1234 | | - | |
1235 | | - | |
| 1227 | + | |
| 1228 | + | |
1236 | 1229 | | |
| 1230 | + | |
| 1231 | + | |
1237 | 1232 | | |
1238 | 1233 | | |
1239 | 1234 | | |
1240 | | - | |
1241 | | - | |
1242 | | - | |
1243 | | - | |
1244 | | - | |
1245 | | - | |
1246 | | - | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
1247 | 1243 | | |
1248 | 1244 | | |
1249 | 1245 | | |
| |||
1255 | 1251 | | |
1256 | 1252 | | |
1257 | 1253 | | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
1258 | 1267 | | |
1259 | 1268 | | |
1260 | 1269 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1972 | 1972 | | |
1973 | 1973 | | |
1974 | 1974 | | |
1975 | | - | |
| 1975 | + | |
1976 | 1976 | | |
1977 | 1977 | | |
1978 | | - | |
1979 | | - | |
1980 | | - | |
1981 | | - | |
1982 | | - | |
| 1978 | + | |
| 1979 | + | |
| 1980 | + | |
1983 | 1981 | | |
1984 | 1982 | | |
1985 | 1983 | | |
| |||
1994 | 1992 | | |
1995 | 1993 | | |
1996 | 1994 | | |
1997 | | - | |
1998 | | - | |
1999 | | - | |
2000 | | - | |
2001 | | - | |
2002 | | - | |
2003 | | - | |
2004 | | - | |
2005 | | - | |
2006 | | - | |
2007 | | - | |
2008 | | - | |
2009 | | - | |
2010 | | - | |
| 1995 | + | |
| 1996 | + | |
| 1997 | + | |
| 1998 | + | |
| 1999 | + | |
| 2000 | + | |
| 2001 | + | |
| 2002 | + | |
| 2003 | + | |
| 2004 | + | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
| 2008 | + | |
| 2009 | + | |
| 2010 | + | |
| 2011 | + | |
| 2012 | + | |
| 2013 | + | |
| 2014 | + | |
| 2015 | + | |
| 2016 | + | |
| 2017 | + | |
2011 | 2018 | | |
2012 | | - | |
| 2019 | + | |
| 2020 | + | |
| 2021 | + | |
| 2022 | + | |
2013 | 2023 | | |
2014 | 2024 | | |
2015 | 2025 | | |
| |||
2018 | 2028 | | |
2019 | 2029 | | |
2020 | 2030 | | |
2021 | | - | |
2022 | | - | |
2023 | 2031 | | |
2024 | 2032 | | |
2025 | 2033 | | |
| |||
3293 | 3301 | | |
3294 | 3302 | | |
3295 | 3303 | | |
3296 | | - | |
3297 | | - | |
3298 | 3304 | | |
3299 | 3305 | | |
3300 | 3306 | | |
| |||
3344 | 3350 | | |
3345 | 3351 | | |
3346 | 3352 | | |
3347 | | - | |
| 3353 | + | |
3348 | 3354 | | |
3349 | 3355 | | |
3350 | | - | |
3351 | | - | |
3352 | | - | |
3353 | | - | |
| 3356 | + | |
| 3357 | + | |
3354 | 3358 | | |
3355 | | - | |
3356 | | - | |
3357 | 3359 | | |
3358 | 3360 | | |
3359 | 3361 | | |
3360 | | - | |
3361 | | - | |
3362 | | - | |
3363 | | - | |
3364 | | - | |
3365 | | - | |
3366 | | - | |
3367 | | - | |
| 3362 | + | |
| 3363 | + | |
| 3364 | + | |
| 3365 | + | |
| 3366 | + | |
| 3367 | + | |
| 3368 | + | |
| 3369 | + | |
| 3370 | + | |
| 3371 | + | |
| 3372 | + | |
| 3373 | + | |
| 3374 | + | |
| 3375 | + | |
| 3376 | + | |
| 3377 | + | |
| 3378 | + | |
| 3379 | + | |
| 3380 | + | |
| 3381 | + | |
| 3382 | + | |
| 3383 | + | |
| 3384 | + | |
3368 | 3385 | | |
3369 | 3386 | | |
3370 | 3387 | | |
| |||
0 commit comments