Skip to content

Python: feat(anthropic): Add response_format support for structured outputs - #3301

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 8 commits into
microsoft:mainfrom
sukeesh:sukeesh/fix-structured-output-anthropic
Jan 21, 2026
Merged

Python: feat(anthropic): Add response_format support for structured outputs#3301
Eduard van Valkenburg (eavanvalkenburg) merged 8 commits into
microsoft:mainfrom
sukeesh:sukeesh/fix-structured-output-anthropic

Conversation

@sukeesh

Copy link
Copy Markdown
Contributor

Motivation and Context

The Anthropic client was missing response_format handling, which is
supported by OpenAI and Azure AI clients. This adds structured output
support using Anthropic's tool use feature.

Changes:

  • Add _create_response_format_tool to convert Pydantic models to tool definitions
  • Force model to use the response format tool when response_format is provided
  • Convert tool call arguments to TextContent for JSON parsing
  • Pass response_format to ChatResponse constructor to trigger try_parse_value

This enables consistent response_format usage across all chat clients.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

@markwallace-microsoft Mark Wallace (markwallace-microsoft) added the python Usage: [Issues, PRs], Target: Python label Jan 20, 2026
@github-actions github-actions Bot changed the title fix(anthropic): Add response_format support for structured outputs Python: fix(anthropic): Add response_format support for structured outputs Jan 20, 2026
@sukeesh Sukeesh (sukeesh) changed the title Python: fix(anthropic): Add response_format support for structured outputs Python: feat(anthropic): Add response_format support for structured outputs Jan 20, 2026
Comment thread python/packages/anthropic/agent_framework_anthropic/_chat_client.py Outdated
Comment thread python/packages/anthropic/agent_framework_anthropic/_chat_client.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@markwallace-microsoft

Mark Wallace (markwallace-microsoft) commented Jan 20, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/anthropic/agent_framework_anthropic
   _chat_client.py36015158%51, 361, 384, 386, 401, 423–426, 435, 437, 468–472, 474, 476–477, 479, 484–485, 487, 518–519, 528, 530–531, 536, 553–554, 596, 611, 615–616, 632, 641, 643, 647–648, 691–693, 695, 708–709, 716–718, 722–724, 728–731, 742, 744, 766, 776, 798–804, 811–812, 820–821, 829–832, 839–840, 846–847, 853–854, 860, 868–870, 874, 881–882, 888–889, 895–896, 902, 910–913, 920–921, 940, 947–948, 967, 989, 991, 1000–1001, 1007, 1029–1030, 1036–1037, 1046–1056, 1063–1069, 1076–1082, 1089–1098, 1105–1108
TOTAL17473271284% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3186 213 💤 0 ❌ 0 🔥 1m 9s ⏱️

@sukeesh

Copy link
Copy Markdown
Contributor Author

Dmytro Struk (@dmytrostruk) / Victor Dibia (@victordibia) / Evan Mattson (@moonbox3) Can I get your review as well on this?

@sukeesh

Sukeesh (sukeesh) commented Jan 21, 2026

Copy link
Copy Markdown
Contributor Author

Dmytro Struk (@dmytrostruk) Eduard van Valkenburg (@eavanvalkenburg) Can you please re-review? I fixed the ruff lint issue that it was complaining.

@sukeesh

Copy link
Copy Markdown
Contributor Author

cc Evan Mattson (@moonbox3)

Merged via the queue into microsoft:main with commit 082f39e Jan 21, 2026
23 checks passed
@sukeesh
Sukeesh (sukeesh) deleted the sukeesh/fix-structured-output-anthropic branch January 22, 2026 06:08
Aris Nguyen (arisng) pushed a commit to arisng/agent-framework that referenced this pull request Feb 2, 2026
…utputs (microsoft#3301)

* fix(anthropic): Add response_format support for structured outputs

* only use from options

* use native way of response format

* ruff lint fix

* address comment; handle dict
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants