Skip to content

Fix serialization of OpenAIPromptExecutionSettings with System.Type in ResponseFormat#13116

Open
shethaadit wants to merge 5 commits into
microsoft:mainfrom
shethaadit:shethaadit/FixBug13107
Open

Fix serialization of OpenAIPromptExecutionSettings with System.Type in ResponseFormat#13116
shethaadit wants to merge 5 commits into
microsoft:mainfrom
shethaadit:shethaadit/FixBug13107

Conversation

@shethaadit

Copy link
Copy Markdown
Contributor

Description:

This pull request addresses a serialization issue where setting the ResponseFormat property of OpenAIPromptExecutionSettings to a System.Type would cause a System.NotSupportedException during JSON serialization. This was due to System.Type not being inherently JSON serializable, which broke scenarios that rely on serializing prompt execution settings.

To resolve this, a custom JsonConverter (TypeOrFunctionResponseFormatConverter) has been introduced. This converter intercepts System.Type objects during serialization and correctly transforms them into the JSON schema format expected by the OpenAI API.

Changes:

  • Created TypeOrFunctionResponseFormatConverter.cs to handle the custom serialization logic for System.Type.
  • Applied the new converter to the ResponseFormat property in OpenAIPromptExecutionSettings.cs.
  • Added a unit test to OpenAIPromptExecutionSettingsTests.cs to verify that serialization now works as expected without throwing an exception.

Validation:

The included unit test, ItCanSerializeResponseFormatAsType, now passes, confirming that the OpenAIPromptExecutionSettings can be successfully serialized when ResponseFormat is a System.Type.

Issue:

Fixes #13107

@shethaadit shethaadit requested a review from a team as a code owner September 12, 2025 22:58
@moonbox3 moonbox3 added .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel labels Sep 12, 2025
@github-actions github-actions Bot changed the title fix(Connectors.OpenAI): Fix serialization of OpenAIPromptExecutionSettings with System.Type in ResponseFormat .Net: fix(Connectors.OpenAI): Fix serialization of OpenAIPromptExecutionSettings with System.Type in ResponseFormat Sep 12, 2025
@shethaadit shethaadit changed the title .Net: fix(Connectors.OpenAI): Fix serialization of OpenAIPromptExecutionSettings with System.Type in ResponseFormat Fix serialization of OpenAIPromptExecutionSettings with System.Type in ResponseFormat Sep 12, 2025
@markwallace-microsoft

Copy link
Copy Markdown
Contributor

@shethaadit can you take a look at the unit test failure

@shethaadit

Copy link
Copy Markdown
Contributor Author

@shethaadit can you take a look at the unit test failure

Hi @markwallace-microsoft, I fixed it and made some code change. Could you please review again?

@shethaadit

Copy link
Copy Markdown
Contributor Author

Hi @markwallace-microsoft, @rogerbarreto, could you please help reviewing again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kernel Issues or pull requests impacting the core kernel .NET Issue or Pull requests regarding .NET code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.Net: OpenAIPromptExecutionSettings.ResponseFormat breaks serialization

4 participants