Skip to content

feat: add Valibot support for structured outputs#1923

Open
Oxygen56 wants to merge 1 commit into
openai:mainfrom
Oxygen56:feat/valibot-structured-outputs-1021
Open

feat: add Valibot support for structured outputs#1923
Oxygen56 wants to merge 1 commit into
openai:mainfrom
Oxygen56:feat/valibot-structured-outputs-1021

Conversation

@Oxygen56

@Oxygen56 Oxygen56 commented Jun 5, 2026

Copy link
Copy Markdown

Adds valibotResponseFormat() for using Valibot schemas with structured outputs.

Summary

This PR adds first-class Valibot support for structured outputs, following the same pattern as the existing Zod integration.

Changes

  • Added src/helpers/valibot.ts with valibotResponseFormat(), valibotTextFormat(), valibotFunction(), and valibotResponsesFunction() helpers
  • Added tests/helpers/valibot.test.ts with comprehensive test coverage
  • Added valibot and @valibot/to-json-schema as optional peer dependencies

How it works

The implementation converts Valibot schemas to JSON Schema using @valibot/to-json-schema (targeting draft-07), then applies the same strict mode transformation used by the Zod helpers. The v.parse() function is used for response parsing.

Usage

const completion = await client.chat.completions.parse({
  model: 'gpt-4o-2024-08-06',
  messages: [{ role: 'user', content: 'What is the weather like?' }],
  response_format: valibotResponseFormat(
    v.object({
      city: v.string(),
      temperature: v.number(),
      units: v.picklist(['c', 'f']),
    }),
    'location',
  ),
});

Closes #1021

Adds valibotResponseFormat() helper for using Valibot schemas
with structured outputs, following the Zod pattern.

Also adds valibotTextFormat(), valibotFunction(), and
valibotResponsesFunction() helpers.

Closes openai#1021

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Oxygen56 Oxygen56 requested a review from a team as a code owner June 5, 2026 17:34

@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: 0d543ded45

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread yarn.lock
@@ -4,17 +4,17 @@

"@aashutoshrathi/word-wrap@^1.2.3":
version "1.2.6"
resolved "https://registry.yarnpkg.com/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz#bd9154aec9983f77b3a034ecaa015c2e4201f6cf"
resolved "https://registry.npmmirror.com/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz"

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 Restore the registry host in the lockfile

This commit rewrites nearly every existing resolved entry from registry.yarnpkg.com to registry.npmmirror.com (Yarn's lockfile records resolved as the tarball URL: https://classic.yarnpkg.com/en/docs/yarn-lock). In CI or user environments that cannot reach that mirror or expect dependencies from the canonical registry, yarn install --frozen-lockfile will now fetch from the mirror and can fail or bypass the expected registry; only the new Valibot-related entries should have been added.

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.

Support Valibot for Structured Outputs

1 participant