Skip to content

Python: Fix runtime response format for responses client#2440

Merged
eavanvalkenburg merged 2 commits intomicrosoft:mainfrom
moonbox3:responses-response-format
Nov 25, 2025
Merged

Python: Fix runtime response format for responses client#2440
eavanvalkenburg merged 2 commits intomicrosoft:mainfrom
moonbox3:responses-response-format

Conversation

@moonbox3
Copy link
Contributor

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_format into Responses text.format and route Pydantic models through parse only when needed. Guard against conflicting response_format/text combinations and reuse mapping for streaming responses.

Description

  • Fix runtime schema for Responses client.
  • Add sample in getting started section.

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.

@moonbox3 moonbox3 self-assigned this Nov 25, 2025
@moonbox3 moonbox3 marked this pull request as ready for review November 25, 2025 01:47
Copilot AI review requested due to automatic review settings November 25, 2025 01:47
@markwallace-microsoft markwallace-microsoft added the documentation Improvements or additions to documentation label Nov 25, 2025
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Nov 25, 2025

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/azure-ai/agent_framework_azure_ai
   _client.py1602882%167–170, 174–175, 177, 218, 220–223, 225, 355–356, 360, 362–363, 365–373, 375
packages/core/agent_framework/openai
   _responses_client.py4609080%98, 144, 151–152, 155–156, 161–162, 165, 172, 191, 198, 201–208, 210, 215, 221, 224, 239, 242–243, 245, 272, 302, 330–331, 358, 362, 379, 384, 426, 490, 565, 570, 574–576, 596, 611–612, 616–618, 666, 686–687, 700–701, 717–718, 756, 758, 796, 798, 807–808, 821, 823, 896–902, 919–924, 943, 961, 971, 973, 991–992, 994–996, 1007–1008, 1011, 1013
TOTAL15538237884% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
2227 130 💤 0 ❌ 0 🔥 54.193s ⏱️

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_config and _convert_response_format to 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.

@eavanvalkenburg eavanvalkenburg added this pull request to the merge queue Nov 25, 2025
Merged via the queue into microsoft:main with commit 2a4802e Nov 25, 2025
24 checks passed
arisng pushed a commit to arisng/agent-framework that referenced this pull request Feb 2, 2026
)

* Fix runtime response format for responses client

* Handle run time schema for Azure AI Client.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants