transform_schema crashes on boolean array items and drops/misconstrains tuple prefixItems
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 20/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Python
- Stelle
- 4.1k
- Fork
- 915
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di anthropics/anthropic-sdk-python
-
beta_tool validation errors reach the model as "Invalid arguments for function X" with no detailForse già presa @mangeshraut712 l’ha presa 32 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
anthropics/anthropic-sdk-python#2033 · 3 commenti ·
-
`AnthropicBedrock` 2.x sends `anthropic_version: 2026-10-21`, which Bedrock rejects for Claude Sonnet 4.5, Opus 4.5 and Opus 4.6Forse già presa @charan-rathore l’ha presa 36 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
anthropics/anthropic-sdk-python#2031 · 1 commento ·
-
Three symlink tests in test_agent_toolset.py are missing the needs_symlinks markerForse già presa @okxint l’ha presa 82 giorni fa. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
anthropics/anthropic-sdk-python#1915 · 3 commenti ·
-
Messages.parse (and AsyncMessages.parse) don't take cache_control?Forse già presa @AlphaFDE l’ha presa 86 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
anthropics/anthropic-sdk-python#1907 · 2 commenti ·
-
Windows: os.fchmod in credential write-back bricks the OAuth refresh tokenForse già presa @OllieinCanada l’ha presa 98 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
anthropics/anthropic-sdk-python#1868 · 1 commento ·
Tutte le issue di anthropics/anthropic-sdk-python
Issue simili
-
bug harness
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
mruangutai/harness#2687 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
modal-labs/modal-client#4158 ·
-
good first issue
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 Mezza giornata Idoneità per principianti 72/100
The-Swarm-Corporation/swarms-rs#168 ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG] SMTP listener now binds to EMAIL_PORT instead of 2525 since the gunicorn switch 5.0.3-ls373Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
linuxserver/docker-healthchecks#137 · 1 commento ·