Skip to content

MLX: object-typed tool parameters returned as JSON strings in tool_calls arguments (MLX side of #75?) #87

Closed

Description

@ecohash-co

Environment: Mac Studio M3 Ultra, 512 GB, macOS 27.2 · TensorFold 0.3.6.2 · MLX 0.32.2 · Vontra/Qwen3.8-Flash-Next-MLX-4bit-MTP, --parallel auto

What happens

When the model writes an object-typed tool parameter as JSON text, the MLX server returns it as a JSON string inside arguments instead of an object. The tool schema says "type": "object", so a client that parses arguments gets str where it expects dict. This looks like the MLX side of what #75 fixes for CUDA ("types Qwen tool parameters by the tool's schema").

Repro (non-streamed, deterministic: TensorFold's seeded sampling returns the same reply each time)

{"model": "m", "max_tokens": 3000, "tool_choice": "auto",
 "chat_template_kwargs": {"enable_thinking": false},
 "messages": [{"role": "user", "content": "Create a job named disk-check that runs `df -h /` every hour."}],
 "tools": [{"type": "function", "function": {
   "name": "automations", "description": "Create a scheduled automation job.",
   "parameters": {"type": "object", "required": ["job"], "properties": {"job": {
     "type": "object", "required": ["name", "schema"], "properties": {
       "name": {"type": "string", "maxLength": 128},
       "schema": {"type": "object", "required": ["trigger"], "properties": {
         "trigger": {"anyOf": [
           {"type": "object", "required": ["script", "cron"], "properties": {
             "script": {"type": "string", "minLength": 1, "maxLength": 65536, "description": "Shell script body"},
             "cron": {"type": "string"}}},
           {"type": "object", "properties": {"event": {"type": "string"}}}]}}}}}}}}}]}

Returned tool_calls[0].function.arguments:

{"job": "{\"name\": \"disk-check\", \"schema\": {\"trigger\": {\"script\": \"df -h /\", \"cron\": \"0 0 * * ?\"}}"}

job is a string containing JSON, not an object.

Comparison

  • The same request without the "description" on script returns a proper object: {"job":{"name":"disk-check","schema":{"trigger":{…}}}}. The description changes the rendered prompt, which changes how the model writes the value; the parser then passes the text through.
  • oMLX 0.7.0.dev4 serving the same model (8-bit MTP) returns job as an object for both variants.

Suggested behaviour: decode a parameter's text as JSON when its schema type is object or array (and coerce integer / number / boolean), as #75 does for CUDA.

Activity

  1. ashhart commented on Sep 29, 2026

    @ashhart
    Owner

    Thanks for the clear report! Fixed in 0.4.0: object and array tool arguments that the model leaves one closing bracket short are now closed, and kept when they then match the schema, so they come back as objects rather than JSON strings. Update with pip install -U git+https://github.com/ashhart/TensorFold.git. If you still see a string where an object belongs, reopen with the tool schema and we'll dig in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions