fix(llm): omit parameters field for no-param tools in OpenAI strict mode#1682
Merged
fix(llm): omit parameters field for no-param tools in OpenAI strict mode#1682
Conversation
Empty-parameter tools generated schema `{"type": "object", "properties": {}}` via
schemars, which OpenAI strict mode rejects with 400 Bad Request ("object schema
missing properties").
Apply the same fix used for Gemini (#1641): detect empty-parameter schemas in
`prepare_tool_params()` and return `None`, causing the `parameters` field to be
omitted entirely via `#[serde(skip_serializing_if = "Option::is_none")]`.
Non-empty schemas are still inlined (`inline_refs_openai`) and normalized
(`normalize_for_openai_strict`) before sending.
Fixes #1673.
f1d6974 to
4b90937
Compare
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
{"type": "object", "properties": {}}) inprepare_tool_params()and returnsNone, causing theparametersfield to be omitted via#[serde(skip_serializing_if = "Option::is_none")]is_empty_object_schema+Option<serde_json::Value>)Test plan
prepare_tool_params_empty_object_returns_none— emptyproperties: {}→Noneprepare_tool_params_no_properties_key_returns_none— absentproperties→Noneprepare_tool_params_non_empty_normalizes_strict— non-empty schema getsadditionalProperties: false+requiredopenai_tool_empty_params_omitted_in_serialization—parameters: Nonenot present in JSON outputFixes #1673.