Skip to content

Conversation

@mklgallegos
Copy link
Contributor

Context

Fixes BRA-3896. When users selected "JSON output" mode in playgrounds with Claude models (including Vertex AI), JSON parsing failed with the error:

invalid JSON: SyntaxError: Unexpected token '`', "```json{ "... is not valid JSON

This was because the proxy only handled json_schema response format for Anthropic, not json_object.

Description

Extended the existing tool-based workaround for structured output to also handle json_object response format. When json_object is specified, the proxy now creates a tool with a generic { type: "object" } schema and forces tool use, same as it does for json_schema. This ensures Claude returns clean JSON instead of markdown-wrapped text.

Changes:

  • Modified condition at proxy.ts:2600 to check for both json_schema and json_object
  • For json_object, use generic { type: "object" } schema (since no specific schema is provided)

Testing

  • Added capture test verifying request transformation for json_object response format
  • confirmed test fails without the fix
  • Verified locally in playground with Claude 4.5 Sonnet - JSON output mode now returns clean JSON

@vercel
Copy link

vercel bot commented Jan 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
ai-proxy Ready Ready Preview, Comment Jan 15, 2026 9:33pm

Review with Vercel Agent

if (parsed.success && parsed.data.type === "json_schema") {
if (
parsed.success &&
(parsed.data.type === "json_schema" || parsed.data.type === "json_object")
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit]: code might be more defensive if we match up-front for the data.type. currently, if someone adds another parsed.data.type, it defaults to type: "object".

i think this is fine since we are migrating away though.

Copy link
Collaborator

@ibolmo ibolmo left a comment

Choose a reason for hiding this comment

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

brief read is that json_object supersedes json_schema. do we know what happens if a user has a json_object but also passes a json_schema? is it possible in the ui for a user to switch to that new format output and still leave behind the schema?

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.

4 participants