Skip to content

Conversation

@sukeesh
Copy link
Contributor

@sukeesh sukeesh commented Jan 20, 2026

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.

@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 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
Copy link
Member

@eavanvalkenburg eavanvalkenburg left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Jan 20, 2026

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
Contributor Author

sukeesh commented Jan 21, 2026

@dmytrostruk / @victordibia / @moonbox3 Can I get your review as well on this?

@sukeesh
Copy link
Contributor Author

sukeesh commented Jan 21, 2026

@dmytrostruk @eavanvalkenburg Can you please re-review? I fixed the ruff lint issue that it was complaining.

@sukeesh
Copy link
Contributor Author

sukeesh commented Jan 21, 2026

cc @moonbox3

@eavanvalkenburg eavanvalkenburg added this pull request to the merge queue Jan 21, 2026
Merged via the queue into microsoft:main with commit 082f39e Jan 21, 2026
23 checks passed
@sukeesh sukeesh deleted the sukeesh/fix-structured-output-anthropic branch January 22, 2026 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants