Repository navigation
Conversation
…chema Lower closed Draft 2020-12 `prefixItems` tuples, open typed-tail tuples (`prefixItems` + dict `items`), and Draft-07 list `items` tuples into `strict_schema["items"]` while preserving positional constraints in `description`, and guard against boolean `items` (`False`/`True`) and `bool` `minItems` values so `transform_schema` does not raise `TypeError`. Fixes anthropics#2064 Assisted-by: Google Antigravity
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2064.
What was wrong
transform_schema(src/anthropic/lib/_parse/_transform.py) had three issues ontype: "array"schemas using JSON Schema Draft 2020-12prefixItems, booleanitems, or Draft-07 listitems:items(items: False/items: True) and Draft-07 listitems:prefixItems+ dictitems):For
{"type": "array", "prefixItems": [{"type": "integer"}], "items": {"type": "string"}, "minItems": 2}, Draft 2020-12 appliesitemsonly to indices>= len(prefixItems). Previously,transform_schemaemitted{"type": "array", "items": {"type": "string"}, "description": "{prefixItems: [{'type': 'integer'}], minItems: 2}"}, forcing index0to be astringand preventing valid[42, "ok"]outputs.$defson Pydantictuple[Step, int]:Pydantic v2 emits
{"type": "array", "prefixItems": [{"$ref": "#/$defs/Step"}, {"type": "integer"}], "minItems": 2, "maxItems": 2}. Previously,strict_schemaomitted"items"altogether, leaving#/$defs/Stepunreferenced in$defs:What changed
transform_tuple_itemsinsrc/anthropic/lib/_parse/_transform.pyto lower closed tuples (items: FalseormaxItems <= len(prefixItems)) and open typed-tail tuples (prefixItems+ dictitems, as well as Draft-07 listitems+additionalItems) intostrict_schema["items"](deduplicated single schema when homogeneous,{"anyOf": [...]}when heterogeneous), while keeping open untyped-tail tuples (prefixItemswithoutitemsand withoutmaxItems <= len(prefixItems), oritems: True) unconstrained onitems.items(False/Trueor list) andprefixItemsin leftoverdescriptionhints instead of passing non-dictitemstotransform_schema.minItemswithnot isinstance(min_items, bool)soTrue/Falseare not treated as1/0.Wire-level / compatibility notes
{"type": "array", "items": {...}}) are unchanged on the wire."items"constraint ({"anyOf": [...]}or single schema) on the wire instead of omitting"items"or raisingTypeError.Verification
tests/lib/_parse/test_transform.pycovering closed Draft 2020-12 tuples (items: False), open typed-tail tuples (prefixItems+ dictitems), open untyped-tail tuples, Draft-07 tuple lists, standaloneitems: False, and Pydantic v2tuple[Step, int]/tuple[int, int].pytest -n0 tests/lib/_parse/(40 passed),ruff check,ruff format --check, andpyrightstrict mode (0 errors, 0 warnings).