Skip to content

fix: accept recursive object schemas for structured output - #24

Draft
Kayvan-Zahiri wants to merge 1 commit into
Factory-AI:mainfrom
Kayvan-Zahiri:codex/fix-recursive-structured-output
Draft

Kayvan-Zahiri wants to merge 1 commit into
Factory-AI:mainfrom
Kayvan-Zahiri:codex/fix-recursive-structured-output

Conversation

@Kayvan-Zahiri

Copy link
Copy Markdown

A recursive Pydantic object model (for example Node with children: list[Node]) emits a root $ref into $defs. The SDK's structured-output check only inspected the root type, so it rejected that valid object model with TypeError: structured output schema must describe a top-level object before a turn could start.

Resolve local JSON Pointer references for the existing top-level-object check, including escaped pointer tokens and cycle detection. The original schema is preserved on the wire and Pydantic still validates the returned object. External, missing, cyclic, and non-object references remain rejected.

Validation:

  • Reproduced the recursive Pydantic model failure on the original code; the regression now passes and adapts a nested object successfully.
  • Added seven cases: recursive model, escaped local pointer and schema preservation, plus five invalid/non-object reference cases.
  • Full offline suite: 1,539 passed, 15 skipped. Live Droid/model tests were skipped; no paid inference or hosted product run was performed.
  • Ruff lint/format, mypy (45 configured files), and Pyright (explicit test-environment Python) pass. Mypy prints the existing unrecognized warn_untyped_fields configuration-option notice.

AI assistance: Codex independently reproduced, implemented, and tested this change with the account owner's authorization. Draft for maintainer review; no human implementation review yet.

This branch has not been deployed

No deployments
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.

1 participant