feat: add Valibot support for structured outputs#1923
Conversation
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>
There was a problem hiding this comment.
💡 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".
| @@ -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" | |||
There was a problem hiding this comment.
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 👍 / 👎.
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
src/helpers/valibot.tswithvalibotResponseFormat(),valibotTextFormat(),valibotFunction(), andvalibotResponsesFunction()helperstests/helpers/valibot.test.tswith comprehensive test coveragevalibotand@valibot/to-json-schemaas optional peer dependenciesHow 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. Thev.parse()function is used for response parsing.Usage
Closes #1021