Skip to content
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

feat: add warning for .optional() usage in OpenAI API schemas #1214

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

silasalberti
Copy link

Add warning for .optional() usage in OpenAI API schemas

This PR adds a warning when .optional() is used in schemas for OpenAI API Structured Outputs, recommending the use of .nullable() instead since optional fields are not currently supported.

Changes

  • Added warning in optional.ts that triggers when openaiStrictMode is true
  • Warning includes explanation and link to documentation
  • Added test to verify warning behavior

Testing

✅ All tests passing (411 total)

  • Added new test case to verify warning is emitted
  • Verified warning message contains correct information
  • Ran full test suite to ensure no regressions

Implementation Details

The warning is implemented in the optional field parser and only triggers when generating schemas specifically for OpenAI API usage (when openaiStrictMode is true). This ensures developers get immediate feedback about unsupported optional fields while keeping the warning relevant only to OpenAI API usage.

Created with help from Devin: https://preview.devin.ai/devin/13e97f93e3b1445c91e60da01b88febd

Fixes #1180

This commit adds a warning when .optional() is used in schemas for OpenAI API
Structured Outputs, recommending the use of .nullable() instead.

- Added warning in optional.ts that triggers when openaiStrictMode is true
- Added test to verify warning behavior

Fixes openai#1180
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Model seems to ignore .optional() fields, and instead uses fasly values such as 0, empty strings etc'
1 participant