Skip to content

docs: update output schema type description - #11016

Merged
gr2m merged 1 commit into
mainfrom
na/16aba4f7
Feb 11, 2026
Merged

docs: update output schema type description#11016
gr2m merged 1 commit into
mainfrom
na/16aba4f7

Conversation

@nicoalbanese

Copy link
Copy Markdown
Contributor

Closes #10222

@nicoalbanese nicoalbanese added the backport Admins only: add this label to a pull request in order to backport it to the prior version label Dec 9, 2025
@ghost ghost added the documentation Improvements or additions to documentation label Dec 9, 2025
type: 'Zod Schema | JSON Schema',
description:
'The schema of the output that the tool produces. Used for validation and type inference.',
'The schema of the output that the tool produces. Used for type inference.',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'The schema of the output that the tool produces. Used for type inference.',
'The schema of the output that the tool produces. Used for validation and type inference.',

The documentation incorrectly states that outputSchema is used for "type inference" only, but the implementation actually uses it for validation as well.

View Details

Analysis

Documentation incorrectly omits validation function of outputSchema

What fails: The documentation for the outputSchema parameter in tool() at content/docs/07-reference/01-ai-sdk-core/20-tool.mdx (line 122) states it is "Used for type inference" only, but the implementation actively validates tool outputs against this schema.

How to reproduce:

  1. Look at packages/ai/src/ui/validate-ui-messages.ts lines 413-417 - the code explicitly calls validateTypes() with tool.outputSchema when toolPart.state === 'output-available'
  2. Run the test "should throw error when tool output validation fails" in packages/ai/src/ui/validate-ui-messages.test.ts line 1114 - it demonstrates that passing a tool output that violates the outputSchema throws an AI_TypeValidationError
  3. Example: passing output: { result: 123 } when schema expects { result: z.string() } fails validation

Result: Documentation is incomplete and misleading - developers don't learn that invalid outputs will be rejected by the validation function

Expected: Documentation should state that outputSchema is used for "validation and type inference" to accurately reflect implementation behavior in validate-ui-messages.ts

@gr2m gr2m left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I trust you over what what agent vercel is saying 😁

@gr2m
gr2m merged commit be02433 into main Feb 11, 2026
25 checks passed
@gr2m
gr2m deleted the na/16aba4f7 branch February 11, 2026 21:55
ghost pushed a commit that referenced this pull request Feb 11, 2026
@ghost ghost removed the backport Admins only: add this label to a pull request in order to backport it to the prior version label Feb 11, 2026
@ghost

ghost commented Feb 11, 2026

Copy link
Copy Markdown

✅ Backport PR created: #12454

ghost pushed a commit that referenced this pull request Feb 11, 2026
This is an automated backport of #11016 to the release-v5.0 branch. FYI
@nicoalbanese

Co-authored-by: Nico Albanese <49612682+nicoalbanese@users.noreply.github.com>
dinwwwh added a commit to middleapi/orpc that referenced this pull request Aug 5, 2026
`createToolFactory` disabled both input and output validation on the
assumption that the AI SDK re-validates against the tool schemas. That
is only true for input: the AI SDK treats `outputSchema` as type
metadata and never validates the value `execute` returns against it
(confirmed in
[vercel/ai#10222](vercel/ai#10222), docs
corrected in
[vercel/ai#11016](vercel/ai#11016)). Procedures
run as tools therefore skipped their `.output()` schemas entirely,
including transforms and defaults.

## Fixes

- Output validation stays enabled; only input validation remains
disabled, since that half is genuinely redundant.
- A handler returning invalid output now rejects with an output
validation error instead of passing through silently.
- Streamed `asyncIteratorObject` outputs validate every yielded event,
and a handler returning a non-iterator now errors instead of being
yielded once as the final result (the old fallback branch became
unreachable and is removed).

## Testing

- A new `generateText` test with a mock model proves the AI SDK returns
schema-violating `execute` output untouched, so it will start failing if
a future `ai` release adds output validation and makes ours redundant.
- Remaining tests cover input validation being skipped, invalid output
rejection, per-event stream validation, and non-iterator rejection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation task-merge-tracking-done

Projects

None yet

Development

Successfully merging this pull request may close these issues.

What is the purpose of outputSchema in toolsets? Contrary to what docs says, it is not used to validate the response output

3 participants