diff --git a/litellm/llms/vertex_ai/common_utils.py b/litellm/llms/vertex_ai/common_utils.py index 85c23d8603c..5028c0cf5c8 100644 --- a/litellm/llms/vertex_ai/common_utils.py +++ b/litellm/llms/vertex_ai/common_utils.py @@ -271,7 +271,7 @@ def supports_response_json_schema(model: str) -> bool: # Gemini 2.0+ and 2.5+ models support responseJsonSchema # Pattern matches: gemini-2.0-*, gemini-2.5-*, gemini-3-*, etc. - gemini_2_plus_pattern = re.compile(r"gemini-([2-9]|[1-9]\d+)\.") + gemini_2_plus_pattern = re.compile(r"gemini-(?:[2-9]|[1-9]\d+)(?:\.|\-)") return bool(gemini_2_plus_pattern.search(model_lower)) diff --git a/tests/test_litellm/llms/vertex_ai/test_vertex_ai_common_utils.py b/tests/test_litellm/llms/vertex_ai/test_vertex_ai_common_utils.py index 4768fa439d5..bebf856ee6e 100644 --- a/tests/test_litellm/llms/vertex_ai/test_vertex_ai_common_utils.py +++ b/tests/test_litellm/llms/vertex_ai/test_vertex_ai_common_utils.py @@ -17,6 +17,7 @@ from litellm.llms.vertex_ai.common_utils import ( get_vertex_project_id_from_url, pop_vertex_request_labels, set_schema_property_ordering, + supports_response_json_schema, vertex_request_labels_from_litellm_params, ) @@ -150,6 +151,23 @@ async def test_get_supports_system_message(): assert result == False +@pytest.mark.parametrize( + "model, expected", + [ + ("gemini-2.0-flash", True), + ("gemini-1.5-pro", False), + ("random-model-name", False), + ("gemini-3-flash-preview", True), + ("gemini-123-pro", True), + ("vertex_ai/gemini-3.1-pro-preview", True), + ], +) +def test_supports_response_json_schema(model: str, expected: bool): + """Test supports_response_json_schema correctly detects Gemini 2.0+ model names""" + + assert supports_response_json_schema(model) == expected + + def test_set_schema_property_ordering_with_excessive_nesting(): """Test set_schema_property_ordering with excessive nesting > max levels +1 deep.""" # generate a schema with excessive nesting @@ -1526,11 +1544,7 @@ def test_vertex_request_labels_from_litellm_params_extracts_requester_metadata() def test_vertex_request_labels_from_litellm_params_accepts_litellm_metadata(): - lp = { - "litellm_metadata": { - "requester_metadata": {"team": "platform", "count": 3} - } - } + lp = {"litellm_metadata": {"requester_metadata": {"team": "platform", "count": 3}}} assert vertex_request_labels_from_litellm_params(lp) == {"team": "platform"}