Skip to content

fix(ai): return validated elements from array output parseCompleteOutput#15734

Merged
lgrammel merged 1 commit into
vercel:mainfrom
AVtheking:fix/array-output-return-validated-elements
Jun 5, 2026
Merged

fix(ai): return validated elements from array output parseCompleteOutput#15734
lgrammel merged 1 commit into
vercel:mainfrom
AVtheking:fix/array-output-return-validated-elements

Conversation

@AVtheking
Copy link
Copy Markdown
Contributor

@AVtheking AVtheking commented Jun 1, 2026

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

  • All commits are signed (PRs with unsigned commits cannot be merged)
  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Related Issues

Fixes #15708

@AVtheking AVtheking force-pushed the fix/array-output-return-validated-elements branch 2 times, most recently from 7730c20 to e04d975 Compare June 1, 2026 07:45
@AVtheking AVtheking force-pushed the fix/array-output-return-validated-elements branch from e04d975 to f32926b Compare June 1, 2026 07:45
@lgrammel lgrammel merged commit d66ae02 into vercel:main Jun 5, 2026
48 of 49 checks passed
@lgrammel lgrammel added the backport Admins only: add this label to a pull request in order to backport it to the prior version label Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Admins only: add this label to a pull request in order to backport it to the prior version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

generateText array output: safeValidateTypes called per element but coerced values discarded (output.ts L281-299)

2 participants