Repository navigation
fix(translator): sanitize tool schemas on the responses to chat path - #18806
Merged
diegosouzapw merged 4 commits intoNov 4, 2026
Conversation
The Responses -> Chat Completions translator forwarded client tool schemas unchanged. Harnesses that deep-truncate their schemas (Codex Desktop) send array keywords replaced by placeholder strings such as "enum": "[MaxDepth]". Strict OpenAI-compatible validators reject these before inference; Ollama Cloud fails with "cannot unmarshal string into Go struct field ToolProperty.enum". Run every emitted function.parameters through the existing stripInvalidSchemaConstructs sanitizer, which the Claude path already uses. The post-pass covers plain function tools, flattened namespace (MCP) sub-tools, tool_search and pre-converted Chat tools. Valid schemas are unchanged. Closes cheaper-inference#18679
gaurav0107
marked this pull request as ready for review
November 3, 2026 00:32
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
This was referenced Nov 4, 2026
diegosouzapw
merged commit Nov 4, 2026
4715073
into
cheaper-inference:release/v3.8.53
3 of 37 checks passed
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
openaiResponsesToOpenAIRequestforwarded client tool schemas to the Chat Completions upstream unchanged. Harnesses that deep-truncate their schemas (Codex Desktop) send array keywords replaced by placeholder strings, e.g."enum": "[MaxDepth]". Ollama Cloud validates tool schemas with Go structs and rejects the request before inference:cannot unmarshal string into Go struct field ToolProperty.enum of type []interface {}.function.parametersthrough the existingstripInvalidSchemaConstructssanitizer, which the Claude path already uses (as suggested in the issue and confirmed by the maintainer). One pass covers plain function tools, flattened namespace (MCP) sub-tools,tool_search, and tools that arrive already in Chat shape.schemaCoercion.tsdoc comment, which said OpenAI targets tolerate these constructs, now notes the strict-validator case.Related Issues
Target Branch
release/v3.8.xbranch (release/v3.8.53), notmainValidation
openaiResponsesToOpenAIRequest, and the schema-coercion suiteseslint+prettier --checkon the changed files, andnpm run check:open-sse-typecheckrelease/v3.8.53tipWithout the fix, the new test fails on the three invalid-schema cases:
With the fix:
Tests Added Or Updated
Changelog fragment:
changelog.d/fixes/18806-responses-chat-tool-schema-sanitize.md.tests/unit/responses-to-chat-tool-schema-sanitize-18679.test.ts(new) asserts on the translated Chat body:"enum": "[MaxDepth]"nested underanyOf[0].properties(the shape from the report) has no string-valuedenumleft, and its valid siblingenumis kept;enumobject ({"0":"a","1":"b"}) becomes["a","b"];additionalProperties: falseis deep-equal to the input.Coverage Notes
open-sse/translator/request/openai-responses.tschange (the newsanitizeChatToolParametershelper and its call site) is covered by the new test file and by the existing translator suites listed above.schemaCoercion.tschanges only a comment.Reviewer Notes
stripInvalidSchemaConstructsalso turns numeric-string constraints into numbers (minimum: "5"to5) and replaces placeholder strings in schema positions with{}. These Chat targets now get the same normalization the Claude path already applies.function.parameters(for exampleweb_searchpassed through as-is) are returned by reference, unchanged.