Skip to content

feat(anthropic): translate output_config/output_format to response_format#1380

Open
idemerge wants to merge 1 commit into
musistudio:mainfrom
idemerge:feat/anthropic-structured-outputs
Open

feat(anthropic): translate output_config/output_format to response_format#1380
idemerge wants to merge 1 commit into
musistudio:mainfrom
idemerge:feat/anthropic-structured-outputs

Conversation

@idemerge
Copy link
Copy Markdown

@idemerge idemerge commented May 6, 2026

Summary

Anthropic's Messages API gained structured outputs in GA on 2025-11-14 via output_config.format, with an earlier beta path using output_format (behind anthropic-beta: structured-outputs-2025-11-13). The AnthropicTransformer previously dropped both fields silently, so any client using structured outputs against an OpenAI-compatible backend (GLM, DeepSeek, Groq, vLLM, etc.) would degrade to free-form text.

This PR translates both shapes into the unified response_format field, matching OpenAI's structured-outputs schema, so existing provider transformers can pass it through unchanged.

Changes

  • packages/core/src/transformer/anthropic.transformer.ts — translate request.output_config?.format ?? request.output_format into result.response_format. Supports json_schema, json_object, and text types. strict defaults to true to mirror Anthropic's guarantee semantics; client can opt out with strict: false.
  • packages/core/src/types/llm.ts — add optional response_format union to UnifiedChatRequest.

Test plan

  • Type-check (tsc --noEmit) introduces zero new errors over master
  • pnpm build passes
  • Manual smoke test against an OpenAI-compatible backend:
curl -X POST http://localhost:3456/v1/messages   -H 'Content-Type: application/json'   -H 'x-api-key: ...'   -d '{
    "model": "your-model",
    "max_tokens": 1024,
    "messages": [{"role":"user","content":"List 3 EU capitals."}],
    "output_config": {
      "format": {
        "type": "json_schema",
        "schema": {
          "type": "object",
          "additionalProperties": false,
          "required": ["capitals"],
          "properties": {
            "capitals": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": false,
                "required": ["country","capital"],
                "properties": {
                  "country": {"type":"string"},
                  "capital": {"type":"string"}
                }
              }
            }
          }
        }
      }
    }
  }'

Expected: content[0].text is a JSON string parseable into an object matching the schema.

Refs

…rmat

Anthropic's Messages API gained structured outputs in GA on 2025-11-14
via output_config.format, with an earlier beta path using output_format
(behind anthropic-beta: structured-outputs-2025-11-13). The
AnthropicTransformer previously dropped both fields silently, so clients
using structured outputs against an OpenAI-compatible backend (GLM,
DeepSeek, Groq, vLLM, etc.) would degrade to free-form text.

Translate both shapes into the unified response_format field matching
OpenAI's structured-outputs schema, so provider transformers can pass it
through unchanged. Supports json_schema, json_object, and text types;
strict defaults to true to mirror Anthropic's guarantee semantics.
@idemerge
Copy link
Copy Markdown
Author

idemerge commented May 6, 2026

Before this PR is merged, you can use the plugin (https://github.com/idemerge/ccr-plugin-structured-outputs) to resolve this issue.

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.

1 participant