Skip to content

feat(helpers): add standard schema support#1997

Open
HAYDEN-OAI wants to merge 2 commits into
mainfrom
dev/hayden/issue-1945-standard-schema-helpers
Open

feat(helpers): add standard schema support#1997
HAYDEN-OAI wants to merge 2 commits into
mainfrom
dev/hayden/issue-1945-standard-schema-helpers

Conversation

@HAYDEN-OAI

Copy link
Copy Markdown
Contributor

Summary

  • add standardResponseFormat(), standardTextFormat(), standardFunction(), and standardResponsesFunction() under openai/helpers/standard-schema
  • support any validator that implements Standard Schema validation plus either Standard JSON Schema conversion or a caller-supplied JSON Schema
  • reuse the existing strict-schema transform so generated schemas stay compatible with Structured Outputs
  • add the new helper entrypoint to JSR exports and generalize one shared strict-schema error from “Zod field” to “Schema field”

Motivation

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 through toStrictJsonSchema(). Callers whose validator only implements Standard Schema validation can supply a schema override 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 $parseRaw hooks 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 --runInBand
  • pnpm exec tsc --noEmit
  • pnpm 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.json
  • git diff --check
  • pnpm run lint

@HAYDEN-OAI HAYDEN-OAI marked this pull request as ready for review July 13, 2026 23:32
@HAYDEN-OAI HAYDEN-OAI requested a review from a team as a code owner July 13, 2026 23:32
@openai-sdks

openai-sdks Bot commented Jul 13, 2026

Copy link
Copy Markdown

OkTest Summary

Failed for Node SDK PR #1997.

View OkTest run #29368665427

SDK merge (8851f021feb8) · head (86fdd75d102d) · base (1cdc0196b434) · OkTest (cb7f0514ccd2)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread src/helpers/standard-schema.ts Outdated
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.

feat: add standard schema support for structured outputs and tools

1 participant