Use Anthropic native output_config.format for structured outputs on supported models#385
Use Anthropic native output_config.format for structured outputs on supported models#385dpdiliberto wants to merge 1 commit intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7aadaeaab5
ℹ️ 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".
| // Use Anthropic's native output_config.format API for proper strict validation | ||
| params.output_config = { | ||
| format: { | ||
| type: "json_schema", | ||
| schema: parsed.data.json_schema.schema, |
There was a problem hiding this comment.
Preserve json_schema strict when building output_config
When response_format is json_schema and the model is in the native path, the proxy only forwards schema into output_config.format and drops json_schema.strict (and other metadata). That means callers who set strict: true will silently lose strict enforcement on these models, which is the core guarantee they asked for. This path is distinct from the other response_format mappings in this file that propagate strict, so the omission is likely unintended and will surface whenever clients rely on strict validation for required fields.
Useful? React with 👍 / 👎.
Summary
This PR updates the proxy to use Anthropic's native
output_config.formatAPI for structured outputs on supported models, ensuring proper validation of required fields whenstrict: trueis configured (https://platform.claude.com/docs/en/build-with-claude/structured-outputs).Problem
Currently, structured outputs are converted to a tool-based approach for all Anthropic models. This doesn't properly enforce required fields from JSON schemas, even when
strict: truewas set, causing required fields to be omitted from responses.Solution
For models that support native structured outputs (Claude Haiku 4.5, Sonnet 4.5, Opus 4.5, and Opus 4.6), we can use Anthropic's native
output_config.formatAPI instead of converting to tools. This ensures proper schema validation and enforcement of required fields.Older models continue to use the tool-based fallback approach for backward compatibility.
Changes
output_config.formatAPI for supported models withjson_schematypejson_objectformatTesting
Tested with Claude Sonnet 4.5 using structured outputs with
strict: true- required fields are now properly enforced.