diff --git a/src/anthropic/lib/_parse/_transform.py b/src/anthropic/lib/_parse/_transform.py index 755ad280d..60353360d 100644 --- a/src/anthropic/lib/_parse/_transform.py +++ b/src/anthropic/lib/_parse/_transform.py @@ -146,7 +146,7 @@ def transform_schema( strict_schema["items"] = transform_schema(items) min_items = json_schema.pop("minItems", None) - if min_items is not None and min_items == 0 or min_items == 1: + if min_items is not None and (min_items == 0 or min_items == 1): strict_schema["minItems"] = min_items elif min_items is not None: # add it back so its treated as an extra property and appended to the description diff --git a/tests/lib/_parse/test_transform.py b/tests/lib/_parse/test_transform.py index 443ca99c9..b1eeb5ffd 100644 --- a/tests/lib/_parse/test_transform.py +++ b/tests/lib/_parse/test_transform.py @@ -117,6 +117,38 @@ def test_array_schema(): ) +def test_array_schema_min_items_zero(): + schema = { + "type": "array", + "items": {"type": "string"}, + "minItems": 0, + } + result = transform_schema(schema) + assert result == snapshot( + { + "type": "array", + "items": {"type": "string"}, + "minItems": 0, + } + ) + + +def test_array_schema_min_items_one(): + schema = { + "type": "array", + "items": {"type": "string"}, + "minItems": 1, + } + result = transform_schema(schema) + assert result == snapshot( + { + "type": "array", + "items": {"type": "string"}, + "minItems": 1, + } + ) + + def test_string_schema_with_format_and_default(): schema = { "type": "string",