Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions litellm/llms/vertex_ai/common_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ def _convert_schema_types(schema, depth=0):
if isinstance(type_val, list) and len(type_val) > 1:
# Convert type arrays to anyOf format
# Fields that are specific to object/array types and should move into anyOf
type_specific_fields = {
type_specific_fields = (
"properties",
"required",
"additionalProperties",
Expand All @@ -907,7 +907,7 @@ def _convert_schema_types(schema, depth=0):
"maxItems",
"minProperties",
"maxProperties",
}
)

any_of: List[Dict[str, Any]] = []
for t in type_val:
Expand Down
15 changes: 9 additions & 6 deletions tests/local_testing/test_amazing_vertex_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -3894,12 +3894,15 @@ def test_gemini_nullable_object_tool_schema_httpx():
}
]

response = litellm.completion(
model="vertex_ai/gemini-2.5-flash",
messages=[{"role": "user", "content": "call the tool"}],
tools=tools,
tool_choice="required",
)
try:
response = litellm.completion(
model="vertex_ai/gemini-2.5-flash",
messages=[{"role": "user", "content": "call the tool"}],
tools=tools,
tool_choice="required",
)
except litellm.RateLimitError:
pytest.skip("Rate limit error")

print(response)

Expand Down
52 changes: 52 additions & 0 deletions tests/test_litellm/llms/vertex_ai/test_vertex_ai_common_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,58 @@ def test_convert_schema_types_type_array_conversion():
assert input_schema["required"] == ["studio"]


def test_convert_schema_types_output_is_stable_across_hash_seeds():
"""
The serialized Vertex schema for a nullable object tool param must be byte-identical
regardless of the interpreter's hash seed. _convert_schema_types used to iterate a set
when moving object-specific fields into the anyOf branch, so the JSON key order of
"properties"/"required" varied per process. That broke byte-level VCR request matching
in CI and forced live Vertex calls (and 429 flakes) on runs whose seed produced the
ordering that was not in the cassette.
"""
import json
import subprocess

script = (
"import json\n"
"from litellm.llms.vertex_ai.common_utils import _build_vertex_schema\n"
"params = {\n"
" 'type': 'object',\n"
" 'additionalProperties': False,\n"
" 'required': ['ticket_id', 'customer_context'],\n"
" 'properties': {\n"
" 'ticket_id': {'type': 'string'},\n"
" 'customer_context': {\n"
" 'type': ['object', 'null'],\n"
" 'additionalProperties': False,\n"
" 'required': ['user_id', 'plan'],\n"
" 'properties': {'user_id': {'type': 'string'}, 'plan': {'type': 'string'}},\n"
" },\n"
" },\n"
"}\n"
"print(json.dumps(_build_vertex_schema(params), separators=(',', ':')))\n"
)
outputs = frozenset(
subprocess.run(
[sys.executable, "-c", script],
env={
**os.environ,
"PYTHONHASHSEED": str(seed),
"LITELLM_LOCAL_MODEL_COST_MAP": "True",
},
capture_output=True,
text=True,
check=True,
).stdout
for seed in range(6)
)
assert len(outputs) == 1

object_variant = json.loads(next(iter(outputs)))["properties"]["customer_context"]["anyOf"][0]
assert object_variant["required"] == ["user_id", "plan"]
assert set(object_variant["properties"]) == {"user_id", "plan"}


def test_fix_enum_empty_strings():
"""
Test _fix_enum_empty_strings function replaces empty strings with None in enum arrays.
Expand Down
Loading