Replies: 2 comments
-
|
Same here. Can't seem to use structured outputs with Python SDK either. Not clear why or how to solve it. |
Beta Was this translation helpful? Give feedback.
-
|
You're correct that structured outputs are not currently supported on Vertex AI through the Anthropic SDK. The documentation you referenced is accurate - it explicitly lists Claude API, Amazon Bedrock, and Microsoft Foundry (beta) as supported platforms. Why Vertex AI is different: The Vertex AI integration goes through Google's infrastructure, which has its own API surface and feature parity timeline. Features like structured outputs require coordination between Anthropic and Google to implement on the Vertex backend. Workarounds for now:
import AnthropicVertex from '@anthropic-ai/vertex-sdk';
const client = new AnthropicVertex();
const response = await client.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
tools: [{
name: 'output_json',
description: 'Output your response as structured JSON. Always use this tool to respond.',
input_schema: {
type: 'object',
properties: {
name: { type: 'string', description: 'Person name'},
age: { type: 'number', description: 'Age in years'},
},
required: ['name', 'age']
}
}],
tool_choice: { type: 'tool', name: 'output_json' },
messages: [{ role: 'user', content: 'Extract: John is 30 years old' }]
});
// Parse from tool_use block
const toolUse = response.content.find(b => b.type === 'tool_use');
const structured = toolUse?.input; // { name: "John", age: 30 }
const response = await client.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
system: 'Always respond with valid JSON only. No markdown, no explanation.',
messages: [{ role: 'user', content: 'Extract name and age: John is 30 years old. Output as {"name": "...", "age": ...}'}]
});Re: documentation request - I agree this should be clearer. A feature matrix showing what's available on each platform (API, Bedrock, Vertex, Foundry) would be very helpful. Consider opening a docs issue at https://github.com/anthropics/anthropic-cookbook or the main SDK repo to surface this request to the team. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
We've been keen to give Anthropic's models a spin via Vertex AI, but this is a blocker for us. After a bit of digging, it seems like there is currently no support for Structured Outputs if going through Vertex. I'd happy to be wrong here!
The only documentation I can find to this end is by implication, with this note:
From the Structured Outputs documentation page.
And in practice I was unable to get this working due to fairly unclear 400's coming back.
If this is indeed not supported, I would suggest adding some clear documentation covering what is and is not supported for each model on each platform. If that documentation exists, please let me know!
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions