Skip to content

chore (provider-utils): replace zod with standard-schema where possible #6184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 47 commits into from
May 15, 2025

Conversation

gr2m
Copy link
Collaborator

@gr2m gr2m commented May 7, 2025

Background

Standard schema allows validation with any schema library that implements it. While we still need to support specific schema libraries in many places because of the JSONSchema conversion, switching to standard schema support where possible will increase the flexibility of the AI SDK.

Summary

Replace zod with standard-schema where users can pass their own schemas for validation.

Related Issues

Closes #5766

schema: Schema<ELEMENT>,
): OutputStrategy<ELEMENT[], ELEMENT[], AsyncIterableStream<ELEMENT>> => {
const arrayOutputStrategy = <OBJECT>(
schema: Schema<OBJECT>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

ELEMENT was on purpose because it is an array element

@gr2m gr2m force-pushed the v5-gr2m/5766-replace-zod-with-standard-schema branch from 6cf46ef to 1d4bb39 Compare May 14, 2025 18:26
@@ -19,7 +20,7 @@ export type Validator<OBJECT = unknown> = {
* Optional. Validates that the structure of a value matches this schema,
* and returns a typed version of the value if it does.
*/
readonly validate?: (value: unknown) => ValidationResult<OBJECT>;
readonly validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no sure if making the validate() method optionally async could cause any problems down the road, but it made the transition easier.

@@ -105,6 +105,7 @@ export function processUIMessageStream<MESSAGE_METADATA = unknown>({
if (messageMetadataSchema != null) {
await validateTypes({
value: mergedMetadata,
// @ts-ignore TODO: Couldn't figure this one out yet ~@gr2m
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@lgrammel if you like have a look at this type error. It's probably something obvious that I'll figure out quickly after some rest.

@lgrammel lgrammel changed the title 🚧 replace zod with standard-schema chore (provider-utils): replace zod with standard-schema where possible May 15, 2025
@lgrammel lgrammel marked this pull request as ready for review May 15, 2025 06:26
@lgrammel lgrammel merged commit faf8446 into v5 May 15, 2025
8 checks passed
@lgrammel lgrammel deleted the v5-gr2m/5766-replace-zod-with-standard-schema branch May 15, 2025 06:33
@gr2m
Copy link
Collaborator Author

gr2m commented May 15, 2025

Thanks for getting it over the line @lgrammel 🙏🏼

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.

2 participants