Skip to content

Fix JSONDecodeError in qwen3_coder tool parser#913

Open
BrunoCerberus wants to merge 1 commit intoml-explore:mainfrom
BrunoCerberus:fix/qwen3-coder-tool-parser-json-fallback
Open

Fix JSONDecodeError in qwen3_coder tool parser#913
BrunoCerberus wants to merge 1 commit intoml-explore:mainfrom
BrunoCerberus:fix/qwen3-coder-tool-parser-json-fallback

Conversation

@BrunoCerberus
Copy link

Summary

Fixes #912

  • _convert_param_value() crashes with JSONDecodeError when the model outputs object/array parameters with single quotes instead of valid JSON
  • Replace the bare json.loads() + separate ast.literal_eval() paths with a single try/except that falls back gracefully

Change

# Before (crashes on single-quoted dicts)
if param_type in _obj_types or ...:
    return json.loads(param_value)
return ast.literal_eval(param_value)

# After (falls back to ast.literal_eval)
try:
    return json.loads(param_value)
except (json.JSONDecodeError, ValueError):
    return ast.literal_eval(param_value)

Test

Reproduced by running Qwen3-Coder-30B-A3B-Instruct via mlx_lm.server with tool-calling requests. The model intermittently outputs {'key': 'value'} instead of {"key": "value"} for object parameters, crashing the server. After this fix the server handles both formats.

The model sometimes outputs tool call parameters with single quotes
or other Python-style literals instead of valid JSON for object/array
types. The bare json.loads() call crashes the server with a
JSONDecodeError.

Fall back to ast.literal_eval() (already used for other types) when
json.loads() fails, matching the existing error handling pattern in
the parser.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

qwen3_coder tool parser crashes with JSONDecodeError on malformed parameters

1 participant