-
Notifications
You must be signed in to change notification settings - Fork 831
Enable specifying "strict" for OpenAI clients via ChatOptions #6552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@eiriktsarpalis, can you help review this? Thanks. |
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIClientExtensions.cs
Outdated
Show resolved
Hide resolved
* Enable specifying "strict" for OpenAI clients via ChatOptions * Address PR feedback
@stephentoub {"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. |
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. |
Closes #6535
Microsoft Reviewers: Open in CodeFlow