fix(tools): strip xAI-unsupported JSON Schema keywords from tool definitions#32080
Merged
steipete merged 1 commit intoopenclaw:mainfrom Mar 2, 2026
Merged
Conversation
…nitions xAI rejects minLength, maxLength, minItems, maxItems, minContains, and maxContains in tool schemas with a 502 error instead of ignoring them. This causes all requests to fail when any tool definition includes these validation-constraint keywords (e.g. sessions_spawn uses maxLength and maxItems on its attachment fields). Add stripXaiUnsupportedKeywords() in schema/clean-for-xai.ts, mirroring the existing cleanSchemaForGemini() pattern. Apply it in normalizeToolParameters() when the provider is xai directly, or openrouter with an x-ai/* model id. Fixes tool calls for x-ai/grok-* models both direct and via OpenRouter.
Contributor
Greptile SummaryThis PR fixes 502 errors when using xAI models (including via OpenRouter) by stripping JSON Schema validation keywords that xAI doesn't support. The implementation follows the existing Key changes:
Why this works: Confidence Score: 5/5
Last reviewed commit: d888bd6 |
This was referenced Mar 2, 2026
steipete
added a commit
that referenced
this pull request
Mar 2, 2026
Contributor
|
Landed via temp rebase onto main. Thanks @asyncjason! |
This was referenced Mar 4, 2026
Closed
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.
Root cause
xAI models (via OpenRouter) reject tool call requests with "Invalid arguments passed to the model" / HTTP 502 when tool schemas contain JSON Schema validation-constraint keywords. Per the xAI structured outputs docs, the following keywords are not supported:
minLength,maxLength,minItems,maxItems,minContains,maxContains. Thesessions_spawntool's attachment fields use several of these, causing every request to xAI models to fail.Fix
Follows the existing
cleanSchemaForGeminipattern:src/agents/schema/clean-for-xai.ts—stripXaiUnsupportedKeywords()recursively removes the unsupported keywords from tool schemas;isXaiProvider()detects direct xAI providers andopenrouter+x-ai/model prefixsrc/agents/pi-tools.schema.ts—normalizeToolParameters()extended withmodelIdoption; newapplyProviderCleaning()helper dispatches Gemini/xAI/passthroughsrc/agents/pi-tools.ts— threadsmodelIdthrough tonormalizeToolParameterssrc/agents/schema/clean-for-xai.test.ts— unit tests for detection and keyword strippingTest plan
src/agents/schema/clean-for-xai.test.ts— coversisXaiProvider()detection (direct xAI, x-ai provider string, OpenRouter + x-ai/ prefix, non-xAI cases) andstripXaiUnsupportedKeywords()(string props, array props, minContains/maxContains, nested objects, anyOf/oneOf/allOf variants, array item schemas, passthrough of non-affected keywords)isXaiProviderreturns true for directxai,x-ai, andopenrouter+x-ai/model prefix; false foropenai,google, undefinedCoded by Claude Code (claude-sonnet-4-6), reviewed and tested by @asyncjason
Fixes #32039