Python: Fix structured_output propagation in ClaudeAgent#4137
Merged
dmytrostruk merged 5 commits intomicrosoft:mainfrom Feb 23, 2026
Merged
Python: Fix structured_output propagation in ClaudeAgent#4137dmytrostruk merged 5 commits intomicrosoft:mainfrom
dmytrostruk merged 5 commits intomicrosoft:mainfrom
Conversation
Capture structured_output from ResultMessage in _get_stream() and propagate it to AgentResponse.value via a custom finalizer. Previously structured_output was silently discarded, making output_format unusable. Fixes microsoft#4095
Member
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where structured_output from Claude's CLI was not being propagated to AgentResponse.value, making the output_format feature unusable. When ClaudeAgent is configured with output_format (JSON Schema), the Claude CLI correctly returns a ResultMessage with a structured_output field, but the agent framework was silently discarding it.
Changes:
- Modified
_get_stream()to capturestructured_outputfromResultMessageand yield it as a finalAgentResponseUpdatewithadditional_properties - Added custom
_finalize_response()method that extractsstructured_outputfrom updates and sets it asresponse.value - Added comprehensive test coverage with 4 new tests covering propagation, absence, streaming, and error scenarios
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| python/packages/claude/agent_framework_claude/_agent.py | Adds structured_output capture in _get_stream(), custom _finalize_response() finalizer that propagates structured_output to response.value |
| python/packages/claude/tests/test_claude_agent.py | Adds 4 comprehensive tests for structured output propagation in various scenarios (present, absent, streaming, error) |
Contributor
Author
|
@microsoft-github-policy-service agree company="Microsoft" |
dmytrostruk
reviewed
Feb 23, 2026
added 2 commits
February 23, 2026 11:41
…rties - Extend AgentResponse.from_updates() to accept optional value parameter - Remove structured_output yield from _get_stream() - Update _finalize_response() to pass value via public API - Update streaming test to use get_final_response()
Add value parameter to both @overload signatures of AgentResponse.from_updates() so mypy recognizes the argument.
dmytrostruk
approved these changes
Feb 23, 2026
eavanvalkenburg
approved these changes
Feb 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
structured_outputfromResultMessagenot being propagated toAgentResponse.valueClaudeAgentis configured withoutput_format, the CLI returnsstructured_outputinResultMessagebut_get_stream()was silently discarding itstructured_outputand makes it available viaresponse.valueFixes #4095
Changes
_agent.py: Capturestructured_outputfromResultMessage, yield as finalAgentResponseUpdatewithadditional_properties, custom finalizer to setresponse.valuetest_claude_agent.py: Add 4 tests for structured output propagation (present, absent, streaming, error case)Test plan