Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

stephentoub
Copy link
Member

@stephentoub stephentoub commented Jun 27, 2025

Closes #6535

Microsoft Reviewers: Open in CodeFlow

@stephentoub stephentoub requested a review from a team as a code owner June 27, 2025 19:40
@github-actions github-actions bot added the area-ai Microsoft.Extensions.AI libraries label Jun 27, 2025
@stephentoub
Copy link
Member Author

@eiriktsarpalis, can you help review this? Thanks.

@stephentoub stephentoub merged commit 41df288 into dotnet:main Jul 3, 2025
6 checks passed
@stephentoub stephentoub deleted the strictoptions branch July 3, 2025 03:53
joperezr pushed a commit that referenced this pull request Jul 8, 2025
* Enable specifying "strict" for OpenAI clients via ChatOptions

* Address PR feedback
@PederHP
Copy link

PederHP commented Jul 29, 2025

@stephentoub
Just had a case in some production code where o4-mini (as an Azure deployment) was not consistent in giving structured output (using GetResponseAsync < T > for request generation) and sometimes responded with:

{"type":"object","properties":{"field1":"foo","field2":true}}

instead of :

{"field1":"foo","field2":true}

which caused it to not deserialize as expected into the response type object.

When setting "strictJsonSchema" to true via ChatOptions the response is consistently returned correctly and GetResponseAsync < T > working as expected.

For developer convenience I think it should arguably default to strict, as figuring out that an AdditionalProperties needs to be set in ChatOptions is going to be difficult for a lot of developers. But I am not sure about the ergonomics of having these ChatOptions have defaults in such a manner. Just wanted to share the observations and fix. I realize this is a model issue and not a framework issue, but it might be useful.

@stephentoub
Copy link
Member Author

I think it should arguably default to strict

We tried that and had to revert. OpenAI has strict rules for schemas that are allowed to be used with strict, and a bunch of schemas folks use (especially coming from arbitrary places with MCP) blow up. We've added in some transforms to help minimize the pain, such that we detect some violations and reconfigure the schema, but it's only a bandaid.

This was referenced Aug 13, 2025
This was referenced Aug 27, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Aug 29, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-ai Microsoft.Extensions.AI libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MEAI: Not possible to set strict mode for OpenAI chat clients.
3 participants