transform_schema crashes on boolean array items and drops/misconstrains tuple prefixItems
評価
調査の方向性
Start in src/anthropic/lib/_parse/_transform.py around lines 200-211, where transform_schema handles items and crashes at json_schema = {**json_schema} when items is a bool or list. Reproduce the three cases in the issue body, and note that pull request #2065 is already open against this work. Done means the three cases no longer crash or drop constraints, with closed and open tuples handled as the expected-behavior section describes.
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
anthropic.transform_schema (src/anthropic/lib/_parse/_transform.py:200-211) has three issues when transforming JSON Schema Draft 2020-12 / Pydantic tuple array schemas (type: "array"):
-
TypeErrorcrash on booleanitems(items: False/items: True) and Draft-07 listitems:
In JSON Schema Draft 2020-12, closed tuple schemas specify"items": falsealongside"prefixItems": [...](and open tuples may specify"items": true).transform_schemachecksif items is not None: strict_schema["items"] = transform_schema(items), passingboolintotransform_schemaand crashing withTypeError: 'bool' object is not a mappingatjson_schema = {**json_schema}. Draft-07 tuple schemas ("items": [{...}, {...}]) similarly crash withTypeError: 'list' object is not a mapping. -
Empty-intersection grammar on open typed tuples (
prefixItems+ dictitems):
In Draft 2020-12,{"type": "array", "prefixItems": [{"type": "integer"}], "items": {"type": "string"}, "minItems": 2}applies"items"only to indices>= len(prefixItems)(so valid arrays are[42, "ok", ...]).transform_schemacurrently dropsprefixItemsintodescriptionwhile keeping"items": {"type": "string"}on the array, which constrains index0tostringas well and prevents the model from producing any valid instance matching the original schema. -
Pydantic
tuple[ModelA, int]drops element constraints and leaves$defsunreferenced:
Pydantic v2 emits{"type": "array", "prefixItems": [{"$ref": "#/$defs/Step"}, {"type": "integer"}], "minItems": 2, "maxItems": 2}fortuple[Step, int]. BecauseprefixItemsis ignored,strict_schemaomits"items"completely (leaving#/$defs/Stepunreferenced in$defsand allowing arbitrary untyped array elements) instead of lowering bounded/closed positional schemas intoitems(anyOfor single schema when homogeneous).
To Reproduce
import pydantic
from anthropic import transform_schema
# 1. Crash on valid Draft 2020-12 closed tuple schema:
transform_schema({
"type": "array",
"prefixItems": [{"type": "integer"}, {"type": "string"}],
"items": False,
})
# TypeError: 'bool' object is not a mapping
# 2. Open typed tuple becomes unsatisfiable (index 0 forced to "string"):
print(transform_schema({
"type": "array",
"prefixItems": [{"type": "integer"}],
"items": {"type": "string"},
"minItems": 2,
}))
# {'type': 'array', 'items': {'type': 'string'}, 'description': "{prefixItems: [{'type': 'integer'}], minItems: 2}"}
# 3. Pydantic tuple[Step, int] loses element schema & orphans #/$defs/Step:
class Step(pydantic.BaseModel):
action: str
class Plan(pydantic.BaseModel):
pair: tuple[Step, int]
print(transform_schema(Plan))
# properties.pair has no 'items' constraint; $defs.Step is unreferenced
Expected behavior
transform_schemashould never crash on booleanitems(False/True) or listitems.- For closed tuples (
items: FalseormaxItems <= len(prefixItems)) and open typed-tail tuples (prefixItems+ dictitems),transform_schemashould lower the allowed element schemas intostrict_schema["items"](deduplicated single schema when homogeneous,{"anyOf": [...]}when heterogeneous) while preserving the positionalprefixItems/itemsconstraints indescription. - For open untyped-tail tuples (
prefixItemswithoutitemsand withoutmaxItems <= len(prefixItems), oritems: True),strict_schemashould omit"items"so tail elements remain unconstrained.
- 主要言語
- Python
- スター
- 4.1k
- フォーク
- 915
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
anthropics/anthropic-sdk-python のほかの issue
-
beta_tool validation errors reach the model as "Invalid arguments for function X" with no detail対応中かも @mangeshraut712 が 32 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
anthropics/anthropic-sdk-python#2033 · コメント 3 件 ·
-
`AnthropicBedrock` 2.x sends `anthropic_version: 2026-10-21`, which Bedrock rejects for Claude Sonnet 4.5, Opus 4.5 and Opus 4.6対応中かも @charan-rathore が 36 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
anthropics/anthropic-sdk-python#2031 · コメント 1 件 ·
-
Three symlink tests in test_agent_toolset.py are missing the needs_symlinks marker対応中かも @okxint が 82 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
anthropics/anthropic-sdk-python#1915 · コメント 3 件 ·
-
Messages.parse (and AsyncMessages.parse) don't take cache_control?対応中かも @AlphaFDE が 86 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
anthropics/anthropic-sdk-python#1907 · コメント 2 件 ·
-
Windows: os.fchmod in credential write-back bricks the OAuth refresh token対応中かも @OllieinCanada が 98 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
anthropics/anthropic-sdk-python#1868 · コメント 1 件 ·
anthropics/anthropic-sdk-python の issue をすべて見る
似ている issue
-
bug harness
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
mruangutai/harness#2687 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
modal-labs/modal-client#4158 ·
-
good first issue
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 半日 初心者へのやさしさ 72/100
The-Swarm-Corporation/swarms-rs#168 ·
メンテナーはふだん 1 日以内に返信
-
[BUG] SMTP listener now binds to EMAIL_PORT instead of 2525 since the gunicorn switch 5.0.3-ls373オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
linuxserver/docker-healthchecks#137 · コメント 1 件 ·