fix(core): a JSON Schema array without items is untyped, not strings - #8264
Open
fei (feiiiiii5) wants to merge 1 commit into
Open
fei (feiiiiii5) wants to merge 1 commit into
fei (feiiiiii5) wants to merge 1 commit into
Conversation
The array branch of _extract_field_type defaulted a missing items schema to str, so {"type": "array"} rejected integers with "Input should be a valid string". An absent items means no constraint on element type per JSON Schema, and Pydantic itself emits {"items": {}} for List[Any], which also hit the str default. Fall back to Any in both cases while keeping minItems/maxItems constraints.
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.
Why
_extract_field_type's array branch treated a missingitemsschema as "items are strings":Two consequences, both wrong against JSON Schema:
{"type": "array"}with noitemsimposes no constraint on element type, yet the generated model rejected integers withnums.0 Input should be a valid string [input_value=1].List[Any]is{"items": {}, "type": "array"}— an empty items schema. That hit the same default ({}has no"type", so the code then diditem_type = strin the inner fallback), so a schema produced by Pydantic itself came back un-validatable throughschema_to_pydantic_model/json_to_pydantic_modelandtype: arraypayloads were refused withinput_value=Truefor a boolean list.Printed at
027ecf0awithautogen_core.__file__resolving inside the checked-out tree:What changed
item_schema = value.get("items", {}), and when the items schema carries no"type"the element type is nowAnyinstead ofstr. A comment records why, sinceAnyis the kind of default a later reader is tempted to "fix" back.$refitems, inline-object items, explicit-but-unsupported type names (UnsupportedKeywordError) and theminItems/maxItemsconstraints are untouched — the two new tests include a constrained case specifically to pin thatunique/length constraints survive the change.Tests
Two cases appended to
python/packages/autogen-core/tests/test_json_to_pydantic.py: an{"type":"array"}with noitemsaccepting mixed element types, and a{"items": {}}array withminItems/uniqueItemsstill enforced.cd python/packages/autogen-core,PYTHONPATH=src:(Parent agent re-ran both sides independently rather than trusting the report; the head summary is
77 passed.)Environment limits, stated plainly:
pytest testsfor the whole package is not collectable here (9 collection errors from[dev]extras that needuv sync), and mypy/pyright did not run for the same reason, so the CI type gates are pending rather than verified.ruff check/ruff format --checkon the two files give identical results at base and head (1 pre-existingI001in the upstream test file, which this diff does not touch), so no new lint findings come from this change.Checklist
schema_to_pydantic_model's existing description already promises JSON Schema semantics that this restores.Heads-up on process, not on the code:
CONTRIBUTING.mdsays most contributions need the Microsoft CLA, so the CLA bot will ask the account owner here — that is not something an agent can satisfy. AndREADME.mdsays AutoGen is in maintenance mode with contributions limited to bug fixes, security patches and docs, which is what this is.