From 79f2e327eb5160be8edba6597d5b73a750a48826 Mon Sep 17 00:00:00 2001 From: S0ngRu1 <1922909737@qq.com> Date: Wed, 13 May 2026 14:26:56 +0800 Subject: [PATCH] test(vertex_ai/gemini): add tests for BadRequestError on null and empty image_url Added new test cases to ensure that a BadRequestError is raised when the image_url key is explicitly set to null or is an empty dictionary. These tests validate the handling of edge cases for the image_url field in the Gemini model. --- .../test_gemini_image_url_missing_field.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_litellm/llms/vertex_ai/gemini/test_gemini_image_url_missing_field.py b/tests/test_litellm/llms/vertex_ai/gemini/test_gemini_image_url_missing_field.py index 0113fa0fc0e..10fc68ecaad 100644 --- a/tests/test_litellm/llms/vertex_ai/gemini/test_gemini_image_url_missing_field.py +++ b/tests/test_litellm/llms/vertex_ai/gemini/test_gemini_image_url_missing_field.py @@ -28,3 +28,25 @@ def test_missing_url_inside_image_url_dict_raises_bad_request_error(): with pytest.raises(litellm.BadRequestError) as exc_info: _gemini_convert_messages_with_history(messages, model="gemini-1.5-pro") assert "'url' field is missing inside" in str(exc_info.value) + + +def test_explicit_null_image_url_raises_bad_request_error(): + """When image_url key is present but explicitly null, a BadRequestError is raised.""" + messages = cast( + List[AllMessageValues], + [{"role": "user", "content": [{"type": "image_url", "image_url": None}]}], + ) + with pytest.raises(litellm.BadRequestError) as exc_info: + _gemini_convert_messages_with_history(messages, model="gemini-1.5-pro") + assert "'image_url' field is missing" in str(exc_info.value) + + +def test_empty_dict_image_url_raises_bad_request_error(): + """When image_url is an empty dict (no url), a BadRequestError is raised.""" + messages = cast( + List[AllMessageValues], + [{"role": "user", "content": [{"type": "image_url", "image_url": {}}]}], + ) + with pytest.raises(litellm.BadRequestError) as exc_info: + _gemini_convert_messages_with_history(messages, model="gemini-1.5-pro") + assert "'url' field is missing inside" in str(exc_info.value)