Skip to content

Structured output not working for opus-4.8 and sonnet 5 #1759

Description

@kamalkraj

Working code for sonnet and opus 4.6

from anthropic import AnthropicBedrock

client = AnthropicBedrock()

response = client.messages.create(
    model="us.anthropic.claude-opus-4-6-v1",
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": "Extract the key information from this email: John Smith (john@example.com) is interested in our Enterprise plan and wants to schedule a demo for next Tuesday at 2pm.",
        }
    ],
    output_config={
        "format": {
            "type": "json_schema",
            "schema": {
                "type": "object",
                "properties": {
                    "name": {"type": "string"},
                    "email": {"type": "string"},
                    "plan_interest": {"type": "string"},
                    "demo_requested": {"type": "boolean"},
                },
                "required": ["name", "email", "plan_interest", "demo_requested"],
                "additionalProperties": False,
            },
        }
    },
)
print(response.content[0].text)

output

{"name":"John Smith","email":"john@example.com","plan_interest":"Enterprise","demo_requested":true}

With opus 4-8 and sonnet 5

output

Traceback (most recent call last):
  File "/Users/kamal.raj/Documents/Github/Trial-Assistant/agent/run.py", line 5, in <module>
    response = client.messages.create(
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kamal.raj/Documents/Github/Trial-Assistant/agent/.venv/lib/python3.12/site-packages/anthropic/_utils/_utils.py", line 294, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kamal.raj/Documents/Github/Trial-Assistant/agent/.venv/lib/python3.12/site-packages/anthropic/resources/messages/messages.py", line 1050, in create
    return self._post(
           ^^^^^^^^^^^
  File "/Users/kamal.raj/Documents/Github/Trial-Assistant/agent/.venv/lib/python3.12/site-packages/anthropic/_base_client.py", line 1536, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kamal.raj/Documents/Github/Trial-Assistant/agent/.venv/lib/python3.12/site-packages/anthropic/_base_client.py", line 1195, in request
    raise self._make_status_error_from_response(response) from None
anthropic.BadRequestError: Error code: 400 - {'message': 'output_config.format: Extra inputs are not permitted'}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions