AI Engineer Guide

Anthropic Ships Guaranteed Structured Outputs for Claude Sonnet 4.5 & Opus 4.1

Anthropic’s latest AI models - Sonnet 4.5 & Opus 4.1 now supports guaranteed structured outputs

This means that whatever schema that we define, we’ll get response in the same format.

Earlier, we had to handle it in consumer end and if there is an error we had to do lot of back and forth API calls to get it fixed.

Now the heavy lifting is done by LLM.

What’s the benefit of using it?

How to use it?

Just define output_format.type as json_schema or "strict": true inside tool declaration.

curl https://api.anthropic.com/v1/messages \
  -H "content-type: application/json" \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "anthropic-beta: structured-outputs-2025-11-13" \
  -d '{
    "model": "claude-sonnet-4-5",
    "max_tokens": 1024,
   "messages": [
      {
        "role": "user",
        "content": "My name is John and I am 28 years old."
      }
    ],
    "output_format": {
      "type": "json_schema",
      "schema": {
        "type": "object",
        "properties": {
          "name": {"type": "string"},
          "age": {"type": "number"}
        },
        "required": ["name", "age"]
      }
    }
  }'

And we’ll be getting response like this

Response format: Valid JSON matching your schema in response.content[0].text

{
  "name": "John",
  "age": 28
}

Reference

Happy parsing content!

#Anthropic #Sonnet-4-5 #Opus-4-1

Stay Updated

Get the latest AI engineering insights delivered to your inbox.

No spam. Unsubscribe at any time.