Repository navigation
fix: encode empty tool properties as JSON object instead of array - #1038
Open
heyzainali wants to merge 1 commit into
Open
heyzainali wants to merge 1 commit into
heyzainali wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Description
If a tool has no parameters, Groq, Mistral, xAI and Z send
"properties": []in the tool definition. An empty PHP array goes throughjson_encodeas[], but these APIs expect an object there, so the request gets rejected.Same root cause as #896, just on the tool definition side instead of the tool call arguments.
Anthropic and OpenRouter already handle this in their own ToolMaps, each a bit differently. Rather than add the same check to four more maps, I added
Tool::parametersAsJsonObject(), which returns the parameters, or an emptystdClasswhen there aren't any, and used it in all six. Output for Anthropic and OpenRouter doesn't change. The Anthropic diff looks bigger than it is because Rector turned the closure into an arrow fn once the local variable was gone.OpenAI and DeepSeek drop
parametersentirely for tools without any, so I left them alone.Tests: a unit test for the new method, a regression test in the Groq, Mistral and xAI
ToolTest, and a newToolTestfor Z since it didn't have one.#977 fixes xAI on its own. I've included xAI here so all four land together, but happy to drop it if you'd rather merge that one.