fix: preserve only originally-required properties in strict tool schemas#471
Open
auriti wants to merge 2 commits intoGitlawb:mainfrom
Open
fix: preserve only originally-required properties in strict tool schemas#471auriti wants to merge 2 commits intoGitlawb:mainfrom
auriti wants to merge 2 commits intoGitlawb:mainfrom
Conversation
Fixes Gitlawb#430. In normalizeSchemaForOpenAI(), the strict branch was adding every property key to required[], including optional ones. This caused providers like Groq, Azure OpenAI, and others to reject valid tool calls with a 400 / tool_use_failed error because the model correctly omits optional arguments but the provider sees them as missing required fields. Root cause: the strict branch used `[...existingRequired, ...allKeys]` instead of `existingRequired.filter(k => k in normalizedProps)`. The Gemini branch already had the correct logic. Fix: align the strict branch with the Gemini branch — only keep properties that were already marked required in the original schema. The additionalProperties: false constraint is preserved as strict-mode providers still require it. Add regression test covering the Read tool schema (file_path required, offset/limit/pages optional).
Contributor
|
please fix conflicts @auriti |
Collaborator
Author
|
Conflicts are now resolved by merging the latest Re-ran the focused |
kevincodex1
approved these changes
Apr 7, 2026
Contributor
kevincodex1
left a comment
There was a problem hiding this comment.
this looks good to me
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #430.
normalizeSchemaForOpenAI()was adding every property key torequired[]whenstrict = true(the default for non-Gemini providers). This caused Groq, Azure OpenAI, and other strict-validation providers to reject valid tool calls with:The model correctly omits optional arguments, but the provider sees them as missing required fields.
Root Cause
strict = true(non-Gemini)required = [...existingRequired, ...allKeys]— adds ALL property keysstrict = false(Gemini)required = existingRequired.filter(k => k in normalizedProps)— correctThe Gemini branch already had the right logic. The strict branch did not.
Changes
src/services/api/openaiShim.tsexistingRequired.filter(k => k in normalizedProps). KeepadditionalProperties: false.src/services/api/openaiShim.test.tsReadtool schema (file_pathrequired,offset/limit/pagesoptional).Issues Addressed
Test Plan
bun test src/services/api/openaiShim.test.ts— all 5 tests passReadtool failure pattern from the issuerequired[]when schema has none)