Python: Fix runtime response format for responses client#2440
Merged
eavanvalkenburg merged 2 commits intomicrosoft:mainfrom Nov 25, 2025
Merged
Python: Fix runtime response format for responses client#2440eavanvalkenburg merged 2 commits intomicrosoft:mainfrom
eavanvalkenburg merged 2 commits intomicrosoft:mainfrom
Conversation
Member
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes runtime response format handling for the OpenAI Responses client by normalizing response_format into the Responses text.format configuration. The changes enable passing JSON schemas at runtime via additional_chat_options without defining Pydantic models upfront.
Key changes:
- Added helper methods
_prepare_text_configand_convert_response_formatto normalize response format configurations - Modified both streaming and non-streaming response methods to handle runtime JSON schemas
- Added a new sample demonstrating runtime JSON schema usage with the Responses client
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
python/packages/core/agent_framework/openai/_responses_client.py |
Core implementation: adds logic to normalize response_format into text configuration, routing Pydantic models through parse and runtime schemas through text.format |
python/samples/getting_started/agents/openai/openai_responses_client_with_runtime_json_schema.py |
New sample demonstrating runtime JSON schema usage with both streaming and non-streaming responses |
python/samples/getting_started/agents/openai/openai_chat_client_with_runtime_json_schema.py |
Added type annotation to chunks variable |
python/samples/getting_started/agents/openai/README.md |
Added documentation entry for the new runtime JSON schema sample |
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
dmytrostruk
approved these changes
Nov 25, 2025
eavanvalkenburg
approved these changes
Nov 25, 2025
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.
Motivation and Context
Previous work was done #2362 to allow for passing in a JSON schema to be used as a response format for OpenAI chat clients. However, when using this for the Responses client, it is breaking.
The PR brings in some changes to normalize
response_formatinto Responsestext.formatand route Pydantic models through parse only when needed. Guard against conflicting response_format/text combinations and reuse mapping for streaming responses.Description
Contribution Checklist