transform_schema crashes on boolean array items and drops/misconstrains tuple prefixItems
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 20/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 4.1k
- Fork
- 915
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của anthropics/anthropic-sdk-python
-
beta_tool validation errors reach the model as "Invalid arguments for function X" with no detailCó thể đã có người làm @mangeshraut712 đã nhận 32 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
anthropics/anthropic-sdk-python#2033 · 3 bình luận ·
-
`AnthropicBedrock` 2.x sends `anthropic_version: 2026-10-21`, which Bedrock rejects for Claude Sonnet 4.5, Opus 4.5 and Opus 4.6Có thể đã có người làm @charan-rathore đã nhận 36 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
anthropics/anthropic-sdk-python#2031 · 1 bình luận ·
-
Three symlink tests in test_agent_toolset.py are missing the needs_symlinks markerCó thể đã có người làm @okxint đã nhận 82 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
anthropics/anthropic-sdk-python#1915 · 3 bình luận ·
-
Messages.parse (and AsyncMessages.parse) don't take cache_control?Có thể đã có người làm @AlphaFDE đã nhận 86 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
anthropics/anthropic-sdk-python#1907 · 2 bình luận ·
-
Windows: os.fchmod in credential write-back bricks the OAuth refresh tokenCó thể đã có người làm @OllieinCanada đã nhận 98 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
anthropics/anthropic-sdk-python#1868 · 1 bình luận ·
Tất cả issue của anthropics/anthropic-sdk-python
Issue tương tự
-
bug harness
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
mruangutai/harness#2687 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
modal-labs/modal-client#4158 ·
-
good first issue
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 72/100
The-Swarm-Corporation/swarms-rs#168 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] SMTP listener now binds to EMAIL_PORT instead of 2525 since the gunicorn switch 5.0.3-ls373Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
linuxserver/docker-healthchecks#137 · 1 bình luận ·