fix: normalize nullable schemas for Vertex Gemini compatibility#8930
fix: normalize nullable schemas for Vertex Gemini compatibility#8930dantti wants to merge 1 commit intoaaif-goose:mainfrom
Conversation
anyOf: [T, {type: null}] and type: [T, null] schemas generated by
schemars for Option<T> fields (e.g. timeout_secs in ShellParams)
are not supported by Vertex Gemini's function calling API. Normalize
them to a scalar type in validate_tool_schemas so they pass through
Bifrost without errors.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Partially fixes issue: aaif-goose#8778 as it's usable with a custom provider
but does not a dedicated one.
Signed-off-by: Daniel Nicoletti <dantti12@gmail.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 523590cc23
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| None | ||
| }; | ||
| if let Some(replacement) = non_null { | ||
| *schema = replacement; |
There was a problem hiding this comment.
Preserve wrapper metadata when unwrapping nullable anyOf
Replacing *schema with the non-null variant here drops any sibling keywords that were on the original schema object (for example description, default, or other annotations alongside anyOf). This occurs for schemas shaped like {..., "anyOf": [T, {"type":"null"}]} and can silently strip tool-parameter metadata for optional fields after validate_tool_schemas, which hurts model guidance and may alter constraints. Prefer removing only the null branch/anyOf while retaining existing sibling fields on the wrapper object.
Useful? React with 👍 / 👎.
anyOf: [T, {type: null}] and type: [T, null] schemas generated by
schemars for Option fields (e.g. timeout_secs in ShellParams)
are not supported by Vertex Gemini's function calling API. Normalize
them to a scalar type in validate_tool_schemas so they pass through
Bifrost without errors.
Partially fixes issue: #8778 as it's usable with a custom provider but does not a dedicated one.
Summary
Vertex AI does not support
"timeout_secs":{"type":["integer","null"],so this changes to"timeout_secs":{"type":"integer"Testing
Using a custom provider with openai pointing to bifrost, then asking questions with vertex/gemini models
Related Issues
Relates to #8778
Feel free to drop this PR if the code quality is questionable, I was able to check with wireshark that it fixes the issue I found but I'm not a rust dev so this is copilot code.
You might argue that the fix should go in bifrost, I have reported the issue there too, but since it seems invalid openai spec msg a fix here wouldn't hurt.