fix: support root-referenced JSON Schema definitions in array outputs - #18802
Merged
Conversation
Co-authored-by: Nick Oates <58091943+n1ckoates@users.noreply.github.com>
Co-authored-by: jpkleemans <5700014+jpkleemans@users.noreply.github.com> Co-authored-by: Nick Oates <58091943+n1ckoates@users.noreply.github.com>
n1ckoates
approved these changes
Aug 12, 2026
Contributor
|
🚀 Published in:
|
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.
Background
OpenAI rejected array structured-output schemas containing root-relative definitions, preventing generateText, streamText, generateObject, and streamObject from returning validated arrays.
Root Cause
Both array schema wrappers moved the complete element schema, including definitions and $defs, under properties.elements.items while references still resolved from the generated root. Live HTTP 400 responses and failing regression tests confirmed the defect.
Summary
Array output wrappers now hoist definitions and $defs to the generated schema root while retaining the remaining element schema under items. A patch changeset was added.
Testing
Added regression coverage for definitions and $defs across Output.array() and the deprecated array output strategy.
End-to-end Validation
pnpm -C examples/ai-functions exec tsx --eval "$(git show HEAD:examples/ai-functions/src/reproduction/issue-6454-openai-array-definitions.ts)"exited successfully; all four live OpenAI array-output paths returned validated elements.Related Issues
Fixes #6454
Closes #18795