[v6.0] fix(ai): return validated elements from array output parseCompleteOutput#16791
Merged
Conversation
…put (#15734) ## Background When using `generateText` with `output: Output.array(...)`, the `parseCompleteOutput` method validated each element with `safeValidateTypes` but discarded `validationResult.value`, returning the raw parsed JSON (`outerValue.elements`) instead. This silently dropped any schema transforms (`.transform()`), coercions (`.coerce`), and defaults (`.default()`), causing the TypeScript return type `Array<ELEMENT>` to be incorrect at runtime. ## Summary - Collect `validationResult.value` during the validation loop and return the validated array instead of `outerValue.elements` - Remove the unsafe `as Array<ELEMENT>` type assertion - Add regression tests including one with a `.transform()` schema that proves returned values come from validation, not raw JSON ## Manual Verification Ran the `output.test.ts` test suite — all 62 tests pass, including the new transform test which would fail on the old code (it would return `{ content: "hello" }` instead of `{ content: "hello", extra: true }`). ## Checklist - [x] All commits are signed (PRs with unsigned commits cannot be merged) - [x] Tests have been added / updated (for bug fixes / features) - [ ] Documentation has been added / updated (for bug fixes / features) - [x] A _patch_ changeset for relevant packages has been added (for bug fixes / features - run `pnpm changeset` in the project root) - [x] I have reviewed this pull request (self-review) ## Related Issues Fixes #15708 (cherry picked from commit d66ae02)
Contributor
|
|
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.
Backport of #15734 to
release-v6.0(clean cherry-pick). Array output previously returned the unvalidated elements, silently dropping schema transforms/coercions/defaults.Part of the v6.0 backport tracking issue #16767.