Fix KeyError: 'name' in qwen3_coder tool parser#1289
Open
DShickle wants to merge 1 commit into
Open
Conversation
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.
Fix KeyError: 'name' in qwen3_coder tool parser
Summary
qwen3_coder.pyraisesKeyError: 'name'when the tool list contains a function dict that doesn't have"name"at the top level of the"function"object. This causes the entire request to fail with a 500-level exception rather than gracefully skipping the malformed entry.Root cause
In
_get_arguments_config(line 29), the function dict is accessed with a hard bracket lookup:Some clients (including Pi and other agentic coding tools) send tool definitions where the
"function"object structure doesn't always include"name"— for example, MCP-proxied tool definitions or tools with non-standard shapes. When this happens, Python raisesKeyError: 'name'and the server throws an unhandled exception.Fix
Replace the hard lookup with
.get():This is a one-line change. If
"name"is absent,function.get("name")returnsNone, which won't match anyfunc_name, so the loop simply continues to the next tool — the correct behaviour.Traceback
Reproduction
mlx_lm.serverwith a Qwen3.6 or Qwen3-Coder model/v1/chat/completionsrequest with tools via an agentic client (Pi, OpenCode, etc.)KeyError: 'name'on the first tool callRelated
Testing
After applying the fix, tool calls from Pi (using MCP-proxied tool definitions) work correctly across multiple turns with no degradation.