Repository navigation
Description
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
- Define a Pydantic model with a nested model
- Call
AnthropicClient.get_responsewith it asresponse_format - Look at
output_config.format.schemain 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.
Metadata
Metadata
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity
github-actions commentedon Nov 11, 2026
Reproduced on main (22b5e75) with a local test that exercises
AnthropicClient._prepare_response_format. For a Pydantic model with a nested model,$defs.Addresshas noadditionalProperties. A dict schema with a nested object has the same gap. Only the root getsadditionalProperties: 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.
kimnamu commentedon Nov 15, 2026
Thanks ni (@nniiovoo) for the clean repro and for flagging the
dict[str, X]trade-off in #10281.AnthropicBedrockClientinherits_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$defs.Address){"name": "Ada", "address": {"city": "London"}}dict[str, str]field{"values": {}}Caveat: both columns ran with the default
mcp-client-2025-04-04beta 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
Happy to leave the fix with you. Claude (via Claude Code) assisted with the live checks and this write-up.
nniiovoo commentedon Nov 15, 2026
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.