fix: sanitize OpenAI tool schemas for strict Codex validation#349
Open
allenyoung25 wants to merge 1 commit intodecolua:masterfrom
Open
fix: sanitize OpenAI tool schemas for strict Codex validation#349allenyoung25 wants to merge 1 commit intodecolua:masterfrom
allenyoung25 wants to merge 1 commit intodecolua:masterfrom
Conversation
Author
|
Thanks for reviewing this. This came from a real Claude Code -> 9router -> Codex failure where MCP tools exposed zero-argument input schemas as I kept the change intentionally narrow: the new helper only sanitizes OpenAI-format function tools at translator emission points, plus one final output safety net. That avoids touching routing, auth, provider selection, or streaming behavior. Validation for this PR included focused schema tests, a full build, and local regression requests that reproduced the failing tool-shape case without triggering the 400 anymore. |
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.
Problem
In some Claude Code -> 9router -> Codex / OpenAI flows, zero-argument MCP tools are forwarded with an object schema like:
{ "type": "object" }Some MCP chains accept that shape, but strict OpenAI/Codex function validation does not. The request then fails with a 400 error similar to:
Root cause
9router currently passes tool schemas through several translator paths without normalizing zero-argument object schemas before emitting OpenAI-format function tools.
Solution
This PR adds a small shared compatibility helper for OpenAI-format tools and applies it at the translator boundaries that can emit function schemas.
The sanitizer:
{ "type": "object", "properties": {} }Scope
The fix is intentionally narrow and localized.
Applied in:
Not changed:
Validation
npm run test:tool-schemanpm run build/v1/chat/completionsusing an intentionally incomplete object schema