Skip to content

Python: [Bug]: Anthropic structured output: nested objects are sent without additionalProperties: false #10280

Description

@nniiovoo

Observed Behavior

When response_format is a Pydantic model with a nested model, AnthropicClient sets additionalProperties: false only on the root of the schema. The nested model ends up in $defs without it. The same happens for nested objects in a dict schema.

Anthropic structured outputs only support additionalProperties: false on objects (docs, and the anthropic SDK's own transform_schema adds it to every object), so these requests get rejected.

Expected Behavior

Every object in the schema gets additionalProperties: false, not only the root. The Bedrock client already does this with _set_additional_properties_false.

Steps to Reproduce

  1. Define a Pydantic model with a nested model
  2. Call AnthropicClient.get_response with it as response_format
  3. Look at output_config.format.schema in the request

Minimal Reproduction

import asyncio
import json
from importlib import import_module

from anthropic import AsyncAnthropic, DefaultAsyncHttpxClient
from pydantic import BaseModel

from agent_framework import Message
from agent_framework.anthropic import AnthropicClient

# The httpx package the anthropic SDK is built on.
httpx = import_module(DefaultAsyncHttpxClient.__mro__[1].__module__.partition(".")[0])


class Address(BaseModel):
    city: str


class Person(BaseModel):
    name: str
    address: Address


sent = {}


def handler(request):
    sent["schema"] = json.loads(request.content)["output_config"]["format"]["schema"]
    return httpx.Response(200, json={
        "id": "msg_1", "type": "message", "role": "assistant", "model": "claude-sonnet-4-5",
        "content": [{"type": "text", "text": '{"name": "Ada", "address": {"city": "London"}}'}],
        "stop_reason": "end_turn", "stop_sequence": None, "usage": {"input_tokens": 1, "output_tokens": 1},
    })


async def main():
    sdk = AsyncAnthropic(api_key="test", http_client=httpx.AsyncClient(transport=httpx.MockTransport(handler)))
    client = AnthropicClient(model="claude-sonnet-4-5", anthropic_client=sdk)
    await client.get_response([Message(role="user", contents=["Who?"])], options={"response_format": Person})

    schema = sent["schema"]
    print("root:", schema.get("additionalProperties"))
    print("$defs.Address:", schema["$defs"]["Address"].get("additionalProperties"))


asyncio.run(main())

Error Messages and Stack Traces

The repro captures the outgoing schema without calling the API.

root: False
$defs.Address: None

Package Versions

agent-framework-core 1.25.0, agent-framework-anthropic 1.0.0b261106 (main at 22b5e75), anthropic 1.17.0

Python Version

Python 3.12

Operating System

macOS

Regression

No

Additional Context

_prepare_response_format in _chat_client.py sets the flag on the root only. A fix could be to walk the schema and set it on every object, like Bedrock does. I have a fix with tests and will open a PR.

AI assistance: I used an AI assistant to help find the cause and write this up. I ran the repro myself.

Acknowledgements

  • I searched existing issues and did not find a duplicate.
  • I personally verified this behavior and the reproduction details are authentic.

Activity

  1. added
    pythonUsage: [Issues, PRs], Target: Python
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Nov 11, 2026
  2. added
    agentsUsage: [Issues, PRs], Target: Single agent
    reproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow
    on Nov 11, 2026
  3. github-actions commented on Nov 11, 2026

    @github-actions
    Contributor

    Reproduced on main (22b5e75) with a local test that exercises AnthropicClient._prepare_response_format. For a Pydantic model with a nested model, $defs.Address has no additionalProperties. A dict schema with a nested object has the same gap. Only the root gets additionalProperties: false. The cause is in _chat_client.py.

    I didn't call the live Anthropic API, so I haven't confirmed that the API rejects the request.

    Support boundary: unclear. I found no maintained spec or decision record that sets it, so a maintainer needs to decide the scope. The fix in #10281 is open and not yet merged or released.

    Run: https://github.com/microsoft/agent-framework/actions/runs/43103510925. This only reproduces and routes the report; maintainers decide priority.

    Generated by Issue Routing for #10280 · copilot · auto · ~25 AIC · ⌖ ~1 AIC · ⊞ 5.2K · ◷

  4. kimnamu commented on Nov 15, 2026

    @kimnamu
    Contributor

    Thanks ni (@nniiovoo) for the clean repro and for flagging the dict[str, X] trade-off in #10281.

    AnthropicBedrockClient inherits _prepare_response_format (_bedrock_client.py:61), so I ran both shapes on Bedrock (us-east-1, anthropic 2.8.0). Claude Haiku 4.5 and Sonnet 5.5 match: main is rejected, #10281 is accepted, and the map field comes back empty as you described.

    response_format main 92838b6 main + #10281
    nested model ($defs.Address) ❌ 400 ✅ {"name": "Ada", "address": {"city": "London"}}
    dict[str, str] field ❌ 400 ✅ {"values": {}}
    # main 92838b60, both models
    nested model:   400 output_config.format.schema: For 'object' type, 'additionalProperties' must be explicitly set to false
    dict[str, str]: 400 output_config.format.schema: For 'object' type, 'additionalProperties: object' is not supported. Please set 'additionalProperties' to false
    

    Caveat: both columns ran with the default mcp-client-2025-04-04 beta removed (BETA_FLAGS, _chat_client.py:99). With it, even a plain call on these models gets a 400 (Unexpected value(s) mcp-client-2025-04-04 for the anthropic-beta header). That looks separate from this issue.

    Probe script and raw output
    # Live Bedrock probe for microsoft/agent-framework#10280 through AnthropicBedrockClient.
    # usage: python -I probe.py <label>   (label = main | pr10281, only printed)
    import asyncio
    import json
    import sys
    
    from pydantic import BaseModel
    
    from agent_framework import Message
    from agent_framework.anthropic import AnthropicBedrockClient
    
    MODELS = [
        "us.anthropic.claude-haiku-4-5-20251001-v1:0",
        "us.anthropic.claude-sonnet-5-5",
    ]
    
    
    class Address(BaseModel):
        city: str
    
    
    class Person(BaseModel):
        name: str
        address: Address
    
    
    class Labels(BaseModel):
        values: dict[str, str]
    
    
    CASES = [
        ("plain", None, "Say hi in one word."),
        ("nested model", Person, "Ada lives in London. Return her name and city."),
        ("dict[str, str]", Labels, "Return the labels color=red and size=L."),
    ]
    
    
    def short(exc: BaseException) -> str:
        while exc.__cause__ is not None:
            exc = exc.__cause__
        return f"{type(exc).__name__}: {str(exc)[:230]}"
    
    
    async def main(label: str, no_mcp_beta: bool) -> None:
        if no_mcp_beta:
            import agent_framework_anthropic._chat_client as cc
            cc.BETA_FLAGS[:] = []  # probe only: drop the default mcp-client beta
            label += " (BETA_FLAGS emptied)"
        for title, fmt, prompt in CASES:
            client = AnthropicBedrockClient(model=MODELS[0], aws_region="us-east-1")
            sent = client._prepare_response_format(fmt)["schema"] if fmt else None
            print(f"## {label} | {title} | sent schema: {json.dumps(sent, separators=(',', ':'))}")
            for model in MODELS:
                client = AnthropicBedrockClient(model=model, aws_region="us-east-1")
                try:
                    resp = await client.get_response(
                        [Message(role="user", contents=[prompt])],
                        options={"response_format": fmt, "max_tokens": 300} if fmt else {"max_tokens": 50},
                    )
                    print(f"   {model}: OK finish={resp.finish_reason} text={resp.text!r}")
                except Exception as exc:  # noqa: BLE001
                    print(f"   {model}: ERR {short(exc)}")
    
    
    asyncio.run(main(sys.argv[1], "--no-mcp-beta" in sys.argv))
    $ python probe.py main
    ## main | plain | sent schema: null
       us.anthropic.claude-haiku-4-5-20251001-v1:0: ERR BadRequestError: Error code: 400 - {'message': 'Unexpected value(s) `mcp-client-2025-04-04` for the `anthropic-beta` header. Please consult our documentation at platform.claude.com/docs or try again without the header.'}
       us.anthropic.claude-sonnet-5-5: ERR BadRequestError: Error code: 400 - {'message': 'Unexpected value(s) `mcp-client-2025-04-04` for the `anthropic-beta` header. Please consult our documentation at platform.claude.com/docs or try again without the header.'}
    ## main | nested model | sent schema: {"$defs":{"Address":{"properties":{"city":{"title":"City","type":"string"}},"required":["city"],"title":"Address","type":"object"}},"properties":{"name":{"title":"Name","type":"string"},"address":{"$ref":"#/$defs/Address"}},"required":["name","address"],"title":"Person","type":"object","additionalProperties":false}
       us.anthropic.claude-haiku-4-5-20251001-v1:0: ERR BadRequestError: Error code: 400 - {'message': "output_config.format.schema: For 'object' type, 'additionalProperties' must be explicitly set to false"}
       us.anthropic.claude-sonnet-5-5: ERR BadRequestError: Error code: 400 - {'message': "output_config.format.schema: For 'object' type, 'additionalProperties' must be explicitly set to false"}
    ## main | dict[str, str] | sent schema: {"properties":{"values":{"additionalProperties":{"type":"string"},"title":"Values","type":"object"}},"required":["values"],"title":"Labels","type":"object","additionalProperties":false}
       us.anthropic.claude-haiku-4-5-20251001-v1:0: ERR BadRequestError: Error code: 400 - {'message': "output_config.format.schema: For 'object' type, 'additionalProperties: object' is not supported. Please set 'additionalProperties' to false"}
       us.anthropic.claude-sonnet-5-5: ERR BadRequestError: Error code: 400 - {'message': "output_config.format.schema: For 'object' type, 'additionalProperties: object' is not supported. Please set 'additionalProperties' to false"}
    $ python probe.py main --no-mcp-beta
    ## main (BETA_FLAGS emptied) | plain | sent schema: null
       us.anthropic.claude-haiku-4-5-20251001-v1:0: OK finish=stop text='Hi!'
       us.anthropic.claude-sonnet-5-5: OK finish=stop text='Hi!'
    ## main (BETA_FLAGS emptied) | nested model | sent schema: {"$defs":{"Address":{"properties":{"city":{"title":"City","type":"string"}},"required":["city"],"title":"Address","type":"object"}},"properties":{"name":{"title":"Name","type":"string"},"address":{"$ref":"#/$defs/Address"}},"required":["name","address"],"title":"Person","type":"object","additionalProperties":false}
       us.anthropic.claude-haiku-4-5-20251001-v1:0: ERR BadRequestError: Error code: 400 - {'message': "output_config.format.schema: For 'object' type, 'additionalProperties' must be explicitly set to false"}
       us.anthropic.claude-sonnet-5-5: ERR BadRequestError: Error code: 400 - {'message': "output_config.format.schema: For 'object' type, 'additionalProperties' must be explicitly set to false"}
    ## main (BETA_FLAGS emptied) | dict[str, str] | sent schema: {"properties":{"values":{"additionalProperties":{"type":"string"},"title":"Values","type":"object"}},"required":["values"],"title":"Labels","type":"object","additionalProperties":false}
       us.anthropic.claude-haiku-4-5-20251001-v1:0: ERR BadRequestError: Error code: 400 - {'message': "output_config.format.schema: For 'object' type, 'additionalProperties: object' is not supported. Please set 'additionalProperties' to false"}
       us.anthropic.claude-sonnet-5-5: ERR BadRequestError: Error code: 400 - {'message': "output_config.format.schema: For 'object' type, 'additionalProperties: object' is not supported. Please set 'additionalProperties' to false"}
    $ python probe.py pr10281 --no-mcp-beta   # main + `gh pr diff 10281 | git apply`
    ## pr10281 (BETA_FLAGS emptied) | plain | sent schema: null
       us.anthropic.claude-haiku-4-5-20251001-v1:0: OK finish=stop text='Hey!'
       us.anthropic.claude-sonnet-5-5: OK finish=stop text='Hi!'
    ## pr10281 (BETA_FLAGS emptied) | nested model | sent schema: {"$defs":{"Address":{"properties":{"city":{"title":"City","type":"string"}},"required":["city"],"title":"Address","type":"object","additionalProperties":false}},"properties":{"name":{"title":"Name","type":"string"},"address":{"$ref":"#/$defs/Address"}},"required":["name","address"],"title":"Person","type":"object","additionalProperties":false}
       us.anthropic.claude-haiku-4-5-20251001-v1:0: OK finish=stop text='{"name": "Ada", "address": {"city": "London"}}'
       us.anthropic.claude-sonnet-5-5: OK finish=stop text='{"name":"Ada","address":{"city":"London"}}'
    ## pr10281 (BETA_FLAGS emptied) | dict[str, str] | sent schema: {"properties":{"values":{"additionalProperties":false,"title":"Values","type":"object"}},"required":["values"],"title":"Labels","type":"object","additionalProperties":false}
       us.anthropic.claude-haiku-4-5-20251001-v1:0: OK finish=stop text='{"values": {}}'
       us.anthropic.claude-sonnet-5-5: OK finish=stop text='{"values":{}}'
    

    Happy to leave the fix with you. Claude (via Claude Code) assisted with the live checks and this write-up.

  5. nniiovoo commented on Nov 15, 2026

    @nniiovoo
    ContributorAuthor

    Thanks for checking it live on Bedrock, that's really helpful. Good to see the dict[str, str] case comes back as an empty object, as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

agentsUsage: [Issues, PRs], Target: Single agentpythonUsage: [Issues, PRs], Target: Pythonready-for-implementationMaintainers agree the problem and direction are ready for implementation.reproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflowtriageUsage: [Issues], Target: All issues that still need to be triaged

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions