Skip to content

feat(helpers): add standard schema support#1997

Merged
HAYDEN-OAI merged 36 commits into
mainfrom
dev/hayden/issue-1945-standard-schema-helpers
Jul 22, 2026
Merged

feat(helpers): add standard schema support#1997
HAYDEN-OAI merged 36 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

237/237 SDK tests passed in 13.043s for Node SDK PR #1997.

Test results — 42 files
Test Result Time
tests/chat-completions-complex-body.test.ts ✅ Passed 245ms
tests/chat-completions-create.test.ts ✅ Passed 388ms
tests/chat-completions-stream.test.ts ✅ Passed 438ms
tests/files-content-binary.test.ts ✅ Passed 185ms
tests/files-create-multipart.test.ts ✅ Passed 257ms
tests/files-list-pagination.test.ts ✅ Passed 268ms
tests/initialize-config.test.ts ✅ Passed 251ms
tests/instance-isolation.test.ts ✅ Passed 271ms
tests/models-list.test.ts ✅ Passed 174ms
tests/responses-background-lifecycle.test.ts ✅ Passed 341ms
tests/responses-body-method-errors.test.ts ✅ Passed 452ms
tests/responses-cancel-timeout.test.ts ✅ Passed 239ms
tests/responses-cancel.test.ts ✅ Passed 417ms
tests/responses-compact-retries.test.ts ✅ Passed 328ms
tests/responses-compact.test.ts ✅ Passed 357ms
tests/responses-create-advanced-stream.test.ts ✅ Passed 183ms
tests/responses-create-advanced.test.ts ✅ Passed 266ms
tests/responses-create-disconnect.test.ts ✅ Passed 1.21s
tests/responses-create-errors.test.ts ✅ Passed 273ms
tests/responses-create-malformed-api-responses.test.ts ✅ Passed 238ms
tests/responses-create-retries.test.ts ✅ Passed 325ms
tests/responses-create-stream-failures.test.ts ✅ Passed 301ms
tests/responses-create-stream-timeout.test.ts ✅ Passed 2.168s
tests/responses-create-stream-wire.test.ts ✅ Passed 2.845s
tests/responses-create-stream.test.ts ✅ Passed 154ms
tests/responses-create-terminal-states.test.ts ✅ Passed 361ms
tests/responses-create-timeout.test.ts ✅ Passed 285ms
tests/responses-create.test.ts ✅ Passed 412ms
tests/responses-delete.test.ts ✅ Passed 378ms
tests/responses-input-items-errors.test.ts ✅ Passed 424ms
tests/responses-input-items-list.test.ts ✅ Passed 208ms
tests/responses-input-items-options.test.ts ✅ Passed 337ms
tests/responses-input-tokens-count-timeout.test.ts ✅ Passed 286ms
tests/responses-input-tokens-count.test.ts ✅ Passed 346ms
tests/responses-malformed-inputs.test.ts ✅ Passed 2.479s
tests/responses-not-found-errors.test.ts ✅ Passed 404ms
tests/responses-parse.test.ts ✅ Passed 284ms
tests/responses-retrieve-retries.test.ts ✅ Passed 431ms
tests/responses-retrieve.test.ts ✅ Passed 347ms
tests/responses-stored-method-errors.test.ts ✅ Passed 865ms
tests/retry-behavior.test.ts ✅ Passed 2.944s
tests/sdk-error-shape.test.ts ✅ Passed 338ms

View OkTest run #29956469948

SDK merge (4e342b227c01) · head (345f5274a29a) · base (39a15b412fc1) · OkTest (d2b5921fc22a)

@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

@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: 32d335f217

ℹ️ 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
Comment thread src/helpers/standard-schema.ts Outdated
Comment thread src/helpers/standard-schema.ts Outdated
Comment thread src/helpers/standard-schema.ts Outdated
Comment thread src/helpers/standard-schema.ts
Comment thread tests/helpers/standard-schema.test.ts Fixed

@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: cc85ea2ca2

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

Copilot AI 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.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Comment thread src/lib/transform.ts

@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: 60486eefdd

ℹ️ 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/lib/transform.ts
Comment thread src/lib/transform.ts

Copilot AI 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.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

@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: 5385043dac

ℹ️ 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/lib/transform.ts Outdated
Comment thread src/lib/transform.ts

Copilot AI 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.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/lib/transform.ts:1301

  • The allOf-merge failure message claims the schema "cannot be merged without changing Draft 7 validation", but this branch is also reached for structural mismatches that don’t actually change Draft 7 validation semantics (e.g., enum array ordering differences). That makes the error misleading for callers.

Consider either canonicalizing order-insensitive arrays (at least enum/required) before equality checks, or adjust the message to describe that the SDK cannot merge the schemas exactly (without rewriting/canonicalizing) for strict Structured Outputs.

  const fail = (): never => {
    throw new Error(
      `Object allOf at \`${
        path.join('/') || '<root>'
      }\` cannot be merged without changing Draft 7 validation.`,
    );

@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: 20418aaac0

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

Copilot AI 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.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

@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: 49772b4dbd

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

Copilot AI 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.

Pull request overview

Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.

Comment thread src/helpers/standard-schema.ts Outdated

@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: 489a430261

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

Copilot AI 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.

Pull request overview

Copilot reviewed 8 out of 9 changed files in this pull request and generated no new comments.

@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: 3ebbe7a9b3

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

@jbeckwith-oai jbeckwith-oai left a comment

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.

I found one blocking issue in the public type contract. Standard Schema declares ~standard.types as optional, so the current output-inference conditional returns unknown for ordinary vendor schemas. I reproduced this with both a spec-shaped StandardSchemaV1<Input, Output> and actual Zod v4: standardResponseFormat(schema, ...).__output and standardFunction({ parameters: schema, function(args) { ... } }) both lose the schema output type. Please fix the conditional and add a regression test using an official/vendor schema whose types property has the standard optional shape.

The runtime conversion/parsing behavior otherwise looked sound in my review. I ran the focused standard-schema/transform/Zod/ResponsesParser suites (270 tests), the full suite (118 passed, 1 skipped; 1,420 tests), lint, build, TypeScript, package/export checks, and additional runtime boundary probes.

Comment thread src/helpers/standard-schema.ts Outdated

Copilot AI 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.

Pull request overview

Copilot reviewed 8 out of 9 changed files in this pull request and generated no new comments.

@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: e5c4c1869c

ℹ️ 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/lib/transform.ts
Comment thread src/lib/transform.ts

Copilot AI 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.

Pull request overview

Copilot reviewed 8 out of 9 changed files in this pull request and generated no new comments.

@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: 2fe00db58e

ℹ️ 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/lib/transform.ts
Comment thread src/lib/transform.ts
Comment thread src/lib/transform.ts
@stainless-app stainless-app Bot mentioned this pull request Jul 22, 2026

Copilot AI 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.

Pull request overview

Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.

Comment thread src/lib/transform.ts
Comment on lines +1114 to +1122
const hasOwnObjectConstraints = Object.keys(jsonSchema).some((keyword) =>
JSON_SCHEMA_OBJECT_KEYWORDS.has(keyword),
);
if (
isRedundantUnionWrapperType(jsonSchema.type, 'object') &&
!hasOwnObjectConstraints &&
Array.isArray(jsonSchema.anyOf) &&
jsonSchema.anyOf.every((branch) => isObjectOnlySchema(branch, root))
) {

@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: 345f5274a2

ℹ️ 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/lib/transform.ts
}

const { branch, index: branchIndex } = realBranches[0]!;
if (typeof branch === 'boolean' || !isObject(branch) || !isObjectOnlySchema(branch, schema)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Promote nullable singleton root unions under the object wrapper

When the root has type: 'object' and its sole real anyOf branch has type: ['object', 'null'], this predicate rejects the branch even though the outer type already excludes null. The schema is exactly equivalent to promoting the branch while retaining the root's scalar object type, but all Standard Schema helpers instead reach the root-anyOf error.

Useful? React with 👍 / 👎.

Comment thread src/lib/transform.ts
jsonSchema.allOf = allOf.map((entry, i) =>
ensureStrictJsonSchema(entry, [...path, 'allOf', String(i)], root),
);
if (allOf.length === 1 && hasOnlyAnnotationSiblings(jsonSchema, 'allOf')) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Collapse parent constraints duplicated by singleton allOf

When a converter emits a scalar schema such as { type: 'string', allOf: [{ type: 'string' }] }, the sole branch merely duplicates the parent constraint, but the parent's type makes this guard fail and the later unsupported-keyword check rejects the schema. The new branch deduplication only compares entries inside allOf, so this exactly representable parent/branch duplicate remains unhandled.

Useful? React with 👍 / 👎.

Comment thread src/lib/transform.ts
Comment on lines +1729 to +1730
if (!parentHasObjectShape && objectBranches.length === 0) {
return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Discard empty-schema allOf branches before classification

For a scalar intersection such as allOf: [{}, { type: 'string' }], neither the parent nor a branch has an object shape, so this return bypasses normalization and the remaining two-branch allOf is rejected later. An empty schema object is validation-equivalent to true and is therefore a neutral intersection branch, so it should be removed alongside the existing boolean true handling.

Useful? React with 👍 / 👎.

Comment on lines +391 to +392
const possibleBranches = record['oneOf'].filter((branch) => branch !== false);
if (!areOneOfBranchesMutuallyExclusive(possibleBranches, normalizedSchema)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Account for the enclosing type in oneOf exclusivity proofs

When an object-typed oneOf wrapper contains untyped object branches with distinct required literal discriminators, such as { type: 'object', oneOf: [{ properties: { kind: { const: 'a' } }, required: ['kind'] }, ...] }, the branches overlap only on non-object values, which the enclosing type: 'object' already rejects. This context therefore makes rewriting to anyOf exact, but the branch-only proof returns false because neither branch independently declares an object type, causing all four Standard Schema helpers to reject valid converter output.

Useful? React with 👍 / 👎.

Comment thread src/lib/transform.ts
Comment on lines +183 to +185
for (const keyword of Object.keys(schemaRecord)) {
if (schemaRecord[keyword] === undefined) {
delete schemaRecord[keyword];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Remove undefined entries from schema maps

When a converter leaves an undefined map member such as properties: { nickname: undefined } or $defs: { Unused: undefined }, JSON serialization would omit that entry, but this pass only deletes undefined keywords from schema objects; the map container itself is never cleaned. The undefined value therefore survives until recursive strictification, where the properties path calls isNullable(undefined, ...) and crashes while reading $ref instead of treating the omitted entry consistently with the existing undefined-placeholder handling.

Useful? React with 👍 / 👎.

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

3 participants