Skip to content

fix(lib): support JSON Schema type arrays in transform_schema (Closes #1876) - #1892

Open
Synxneuos wants to merge 1 commit into
anthropics:mainfrom
Synxneuos:fix/transform-schema-type-array-1876
Open

fix(lib): support JSON Schema type arrays in transform_schema (Closes #1876)#1892
Synxneuos wants to merge 1 commit into
anthropics:mainfrom
Synxneuos:fix/transform-schema-type-array-1876

Conversation

@Synxneuos

Copy link
Copy Markdown

Summary

Closes #1876

When a JSON Schema specifies type as an array (e.g., {"type": ["string", "null"]} as generated by Pydantic Optional[T] or Zod .nullable()), transform_schema() previously raised an AssertionError due to unmatched type branches in _transform.py.

Changes

  • In src/anthropic/lib/_parse/_transform.py:
    • Added support for list types in transform_schema(), mapping type: [T1, T2] to anyOf: [{"type": T1}, {"type": T2}].
    • Updated type annotations for type_ to Optional[SupportedTypes | list[SupportedTypes]].
    • Allowed is_list(type_) in the terminal validation pass to prevent false assert_never triggers.
  • In tests/lib/_parse/test_transform.py:
    • Added unit tests test_type_array() and test_type_array_in_object().

Verification

  • All 16 unit tests in tests/lib/_parse/test_transform.py passed (16 passed in 6.03s).

@Synxneuos
Synxneuos requested a review from a team as a code owner August 28, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

transform_schema raises AssertionError on type arrays (e.g. type: ["string","null"])

1 participant