diff --git a/litellm/llms/anthropic/output_schema.py b/litellm/llms/anthropic/output_schema.py index 803e2e4a14d..d977c691d1a 100644 --- a/litellm/llms/anthropic/output_schema.py +++ b/litellm/llms/anthropic/output_schema.py @@ -152,6 +152,7 @@ def _object_fields(declared_type: object, schema: Mapping[str, object]) -> Mappi return {"additionalProperties": False} if ( declared_type is None + and "enum" not in schema and _as_schema(schema.get("properties")) is not None and not _COMPOSITION_KEYS & schema.keys() ): diff --git a/tests/unit/llms/anthropic/test_anthropic_output_schema.py b/tests/unit/llms/anthropic/test_anthropic_output_schema.py index 273f3c4cfd8..4133e165e9e 100644 --- a/tests/unit/llms/anthropic/test_anthropic_output_schema.py +++ b/tests/unit/llms/anthropic/test_anthropic_output_schema.py @@ -103,3 +103,4 @@ def test_nullable_object_enum_keeps_its_type_dropped_instead_of_forcing_object() ) assert shaped == {"properties": {"a": {"type": "string"}}, "enum": [None]} + assert shape_claude_output_schema(shaped) == shaped