feat(helpers): add standard schema support#1997
Open
HAYDEN-OAI wants to merge 2 commits into
Open
Conversation
OkTest Summary❌ Failed for Node SDK PR #1997. SDK merge ( |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c4080eb882
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
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.
Summary
standardResponseFormat(),standardTextFormat(),standardFunction(), andstandardResponsesFunction()underopenai/helpers/standard-schemaMotivation
Fixes #1945.
The SDK currently has Zod-specific helpers, while #1021 and the open Valibot-specific PR #1923 show the pressure to add another helper family for each schema library. Standard Schema provides a vendor-neutral validation interface, and Standard JSON Schema provides a vendor-neutral JSON Schema conversion interface, so the SDK can support Zod, Valibot, ArkType, and future libraries without adding runtime dependencies or per-library adapters.
Behavior
The helpers use
schema["~standard"].jsonSchema.input({ target: "draft-07" })for the model-facing schema, then pass that schema throughtoStrictJsonSchema(). Callers whose validator only implements Standard Schema validation can supply aschemaoverride instead.Parsed response content and tool arguments flow through
schema["~standard"].validate(), preserving the schema’s inferred output type for parsed content and callback arguments.Validation is intentionally synchronous. The SDK’s existing
$parseRawhooks are synchronous, so Promise-returning Standard Schema validators fail with an actionable error instead of introducing hidden async behavior into parse helpers.Compatibility
This is additive and introduces no new runtime or peer dependencies. Existing Zod helpers are unchanged. The only existing behavior change is clearer shared-transform error wording for non-Zod schemas.
Validation
pnpm exec jest tests/helpers/standard-schema.test.ts tests/helpers/zod.test.ts tests/lib/transform.test.ts --runInBandpnpm exec tsc --noEmitpnpm exec prettier --check src/helpers/standard-schema.ts src/lib/transform.ts tests/helpers/standard-schema.test.ts tests/helpers/zod.test.ts tests/lib/transform.test.ts jsr.jsongit diff --checkpnpm run lint