This commit is contained in:
Yufeng He 2026-08-27 15:32:51 -05:00 committed by GitHub
commit cd18c9e405
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 35 additions and 2 deletions

View file

@ -3746,14 +3746,18 @@ def _remove_strict_from_schema(schema):
"""
Relevant Issues: https://github.com/BerriAI/litellm/issues/6136, https://github.com/BerriAI/litellm/issues/6088
"""
schema_map_keys = {"properties", "patternProperties", "$defs", "definitions"}
if isinstance(schema, dict):
# Remove the 'additionalProperties' key if it exists and is set to False
if "strict" in schema:
del schema["strict"]
# Recursively process all dictionary values
for key, value in schema.items():
_remove_strict_from_schema(value)
if key in schema_map_keys and isinstance(value, dict):
for prop_schema in value.values():
_remove_strict_from_schema(prop_schema)
else:
_remove_strict_from_schema(value)
elif isinstance(schema, list):
# Recursively process all items in the list

View file

@ -45,6 +45,35 @@ def reset_mock_cache():
_model_cache.flush_cache()
def test_remove_strict_from_schema_preserves_property_named_strict():
from litellm.utils import _remove_strict_from_schema
schema = {
"type": "object",
"strict": True,
"properties": {
"strict": {"type": "boolean"},
"field": {"type": "string", "strict": True},
},
"patternProperties": {
"strict": {"type": "number", "strict": True},
},
"$defs": {
"strict": {"type": "object", "strict": True},
},
"required": ["strict", "field"],
}
result = _remove_strict_from_schema(schema)
assert "strict" not in result
assert result["properties"]["strict"] == {"type": "boolean"}
assert result["properties"]["field"] == {"type": "string"}
assert result["patternProperties"]["strict"] == {"type": "number"}
assert result["$defs"]["strict"] == {"type": "object"}
assert result["required"] == ["strict", "field"]
# Test 1: Check trimming of normal message
def test_basic_trimming():
litellm._turn_on_debug()