qwen3_coder tool parser returns raw string for parameters whose schema has no top-level "type" (oneOf/anyOf)

Open Beginner friendly
#1,907 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
ai

Research direction

Start in mlx_lm/tool_parsers/qwen3_coder.py at _convert_param_value() and reproduce the behavior with the oneOf schema and model output given in the issue. Confirm that parameters without a top-level type are parsed as JSON objects when valid, while invalid JSON still remains a raw string; done means arguments.plugin is a dict for the supplied reproduction.

Written by the indexing model from the issue text.

Description

mlx-lm 0.31.3, mlx_lm/tool_parsers/qwen3_coder.py, _convert_param_value()

If a tool parameter's JSON schema has no top-level "type" key (e.g. a oneOf of object
branches, which is valid JSON Schema and what OpenAI-style tool definitions allow),
the parser falls into:

else:
    param_type = "string"

and returns the model's XML parameter body verbatim. The model emitted a JSON object,
so the client receives "plugin": "{\"kind\": \"new\", ...}" (a string) instead of an
object, and schema validation on the client fails.

Repro schema:
{"plugin": {"oneOf": [
{"type":"object","properties":{"kind":{"const":"new"},"idPrefix":{"type":"string"}},"required":["kind","idPrefix"]},
{"type":"object","properties":{"kind":{"const":"existing"},"pluginId":{"type":"string"}},"required":["kind","pluginId"]}]}}
Model output:
<function=f><parameter=plugin>{"kind": "new", "idPrefix": "abc"}
Actual: arguments.plugin == '{"kind": "new", "idPrefix": "abc"}' (str)
Expected: arguments.plugin == {"kind": "new", "idPrefix": "abc"} (dict)

Suggested fix: when "type" is absent, attempt json.loads(param_value) and fall back
to the raw string on failure. Patch:

else:
    try:
        return json.loads(param_value)
    except (json.JSONDecodeError, ValueError):
        return param_value

Seen via oMLX 0.7.0.dev3 serving Qwen3.6-35B-A3B; the client was DeepSeek Harness
(dsh), whose cordis_define tool uses a oneOf parameter.

Dominant language
Python
Stars
7.1k
Forks
1.1k
Avg merge
3d 7h
Merged PRs (30d)
54

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ml-explore/mlx-lm

All issues in ml-explore/mlx-lm

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.