[GH-ISSUE #4630] [Engine] An array or object tool parameter with a raw newline inside a string reaches the client as a string #2099

Open
opened 2026-11-04 01:56:40 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @Efs-O on GitHub (Oct 29, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4630

Area

[Engine] (speed, kernels, models, the server and API)

Desktop app, Terminal or source?

Desktop app (Windows, Linux or Mac)

What happened

A tool call whose array or object parameter holds multi-line text reaches the client as a string instead of the array or object, and the client rejects the call.

In the Qwen XML form (<parameter=edits>…</parameter>) the model writes the value as raw text. For a parameter whose declared type is not string, the parser runs json.loads(value) and, when that raises, silently passes the raw text through as a string:

  • parse_tool_call, serve/frontend.py:931-935 on main 46c152a1
  • the streaming parser's raw state, serve/frontend.py:1274-1277

The model typically writes a line break inside a JSON string as a real newline, not as \n. That is natural in this format and is what an agent editing a Markdown file or source code does. Python's default json.loads (strict=True) refuses a raw control character inside a string, so the whole value falls back to a string:

Invalid control character at: line 1 column 74 (char 73)

The value itself was a correct array of {"old_str", "new_str"} objects. json.loads(value, strict=False) parses it into exactly that array.

Seen with Forge (VS Code agent) as the client, on an edit_file call whose edits parameter is declared as an array. The client answered edits arrived as a string, not an array and is not valid JSON. The model recovered by switching to a flat single-edit form, but it costs a round each time, and it happens often on long agent sessions that edit Markdown.

Expected: a raw newline or tab inside a string in a non-string parameter parses as part of that string.

Suggested fix: json.loads(value, strict=False) at both sites. Valid JSON parses exactly as before. The only change is that raw control characters inside strings are accepted, which is what the XML parameter format produces. A parameter that is still not JSON keeps today's fallback.

Smallest steps or command that reproduce it

import json
s = '[{"old_str": "a", "new_str": "line one\nline two"}]'   # a real newline inside new_str
json.loads(s)                 # ValueError: Invalid control character at: line 1 column 39 (char 38)
json.loads(s, strict=False)   # [{'old_str': 'a', 'new_str': 'line one\nline two'}]

Feeding parse_tool_call a <tool_call><function=edit_file><parameter=edits> block with that value and a schema declaring edits as array returns arguments["edits"] as str.

Reproduction status

Reproduced locally

Strata version

engine 0.1.52 (the code paths above checked on main 46c152a1)

Graphics card, memory and system

2x RTX 5060 Ti 16 GB + RTX 3060 12 GB, Windows 10 Pro

Model, size and settings

Qwen3.8-Flash-Next IQ2_XS, 400K context. The model is not the cause: the parameter value it wrote was correct JSON apart from the raw newlines.

Originally created by @Efs-O on GitHub (Oct 29, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/4630 ### Area [Engine] (speed, kernels, models, the server and API) ### Desktop app, Terminal or source? Desktop app (Windows, Linux or Mac) ### What happened A tool call whose array or object parameter holds multi-line text reaches the client as a **string** instead of the array or object, and the client rejects the call. In the Qwen XML form (`<parameter=edits>…</parameter>`) the model writes the value as raw text. For a parameter whose declared type is not `string`, the parser runs `json.loads(value)` and, when that raises, silently passes the raw text through as a string: - `parse_tool_call`, `serve/frontend.py:931-935` on main `46c152a1` - the streaming parser's `raw` state, `serve/frontend.py:1274-1277` The model typically writes a line break inside a JSON string as a real newline, not as `\n`. That is natural in this format and is what an agent editing a Markdown file or source code does. Python's default `json.loads` (`strict=True`) refuses a raw control character inside a string, so the whole value falls back to a string: ``` Invalid control character at: line 1 column 74 (char 73) ``` The value itself was a correct array of `{"old_str", "new_str"}` objects. `json.loads(value, strict=False)` parses it into exactly that array. Seen with Forge (VS Code agent) as the client, on an `edit_file` call whose `edits` parameter is declared as an array. The client answered `edits arrived as a string, not an array and is not valid JSON`. The model recovered by switching to a flat single-edit form, but it costs a round each time, and it happens often on long agent sessions that edit Markdown. **Expected:** a raw newline or tab inside a string in a non-`string` parameter parses as part of that string. **Suggested fix:** `json.loads(value, strict=False)` at both sites. Valid JSON parses exactly as before. The only change is that raw control characters inside strings are accepted, which is what the XML parameter format produces. A parameter that is still not JSON keeps today's fallback. ### Smallest steps or command that reproduce it ```python import json s = '[{"old_str": "a", "new_str": "line one\nline two"}]' # a real newline inside new_str json.loads(s) # ValueError: Invalid control character at: line 1 column 39 (char 38) json.loads(s, strict=False) # [{'old_str': 'a', 'new_str': 'line one\nline two'}] ``` Feeding `parse_tool_call` a `<tool_call><function=edit_file><parameter=edits>` block with that value and a schema declaring `edits` as `array` returns `arguments["edits"]` as `str`. ### Reproduction status Reproduced locally ### Strata version engine 0.1.52 (the code paths above checked on main `46c152a1`) ### Graphics card, memory and system 2x RTX 5060 Ti 16 GB + RTX 3060 12 GB, Windows 10 Pro ### Model, size and settings Qwen3.8-Flash-Next IQ2_XS, 400K context. The model is not the cause: the parameter value it wrote was correct JSON apart from the raw newlines.
Author
Owner

@LagutArt commented on GitHub (Oct 30, 2026):

[RU]

Добавлю от себя небольшое наблюдение.

Если аргумент в properties указан как "type": "string", то сервер возвращает экранированный Unicode. Если аргумент указан как "type":"array","items":{"type":"string"}} то возвращаются Unicode строки.

Что забавно сама модель генерирует именно Unicode. И это видно в её последнем ответе.

[EN] (Yandex Translate)

I’ll add a small observation of my own.

If the argument in properties is specified as "type": "string", the server returns escaped Unicode. If the argument is specified as "type":"array","items":{"type":"string"}}, then Unicode strings are returned.

What’s funny is that the model itself generates Unicode. And this is evident in its last response.

{
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "list_directory_detailed",
        "description": "Return detailed information about files and folders in a directory, including sizes.",
        "parameters": {
          "type": "object",
          "properties": {
            "path": { "type": "string", "description": "Path to the target directory" }
          },
          "required": ["path"]
        }
      }
    },
    {
      "type": "function",
      "function": {
        "name": "search_in_file",
        "description": "Searches for one or more substrings in a file and returns matching lines with their line numbers. A line is returned if it contains any of the search terms.",
        "parameters": {
          "type": "object",
          "properties": {
            "path": { "type": "string", "description": "Full path to the file" },
            "queries": {
              "type": "array",
              "description": "The text to search for (case-sensitive)",
              "items": { "type": "string" }
            }
          },
          "required": ["path", "queries"]
        }
      }
    }
  ],
  "messages": [
    {
      "role": "user",
      "content": "Try to find the files in the non‑existent directory \"Папка\"."
    },
    {
      "role": "assistant",
      "content": "",
      "reasoning_content": "The user is asking me to look for files in a directory called \"Папка\" (which means \"Folder\" in Russian). This directory doesn't exist, but I should try to list it anyway to demonstrate what happens.\n",
      "tool_calls": [
        {
          "id": "call_0ad763dd4ed144a2861bb4ef",
          "type": "function",
          "function": {
            "name": "list_directory_detailed",
            "arguments": "{\"path\":\"\\u041f\\u0430\\u043f\\u043a\\u0430\"}"
          }
        }
      ]
    },
    {
      "tool_call_id": "call_0ad763dd4ed144a2861bb4ef",
      "role": "tool",
      "content": "{\"Error\": \"Directory 'Папка' does not exist.\"}"
    },
    {
      "role": "user",
      "content": "Try to find the word \"Привет\" in the non‑existent file `Файл.txt`."
    },
    {
      "role": "assistant",
      "content": "",
      "reasoning_content": "The user wants me to search for the word \"Привет\" in a non-existent file called \"Файл.txt\". Let me try to search in this file anyway to demonstrate what happens.\n",
      "tool_calls": [
        {
          "id": "call_e62411203ab74225a175950e",
          "type": "function",
          "function": {
            "name": "search_in_file",
            "arguments": "{\"path\":\"\\u0424\\u0430\\u0439\\u043b.txt\",\"queries\":[\"Привет\"]}"
          }
        }
      ]
    },
    {
      "tool_call_id": "call_e62411203ab74225a175950e",
      "role": "tool",
      "content": "{\"error\":\"File not found.\"}"
    },
    {
      "role": "assistant",
      "content": "As expected, the file \"Файл.txt\" does not exist, and the search returned an error: **\"File not found.\"**",
      "reasoning_content": "The file doesn't exist, so the search returned an error saying \"File not found.\"\n"
    },
    {
      "role": "user",
      "content": "Right now, I deliberately disabled your tools. Your task is to purposefully call the tools again with the same arguments."
    },
    {
      "role": "assistant",
      "content": "My tools are currently disabled, so I'm unable to call any tools — including `list_directory_detailed` or `search_in_file` — regardless of the arguments. There is nothing I can do on this turn other than inform you that no tool call can be made in this state.",
      "reasoning_content": "The user says they've deliberately disabled my tools and asks me to \"purposefully call the tools again with the same arguments.\" Since the tools are disabled, I cannot actually call any tools. I should inform the user that my tools are currently disabled/unavailable, so I'm unable to make any tool calls.\n"
    },
    {
      "role": "user",
      "content": "DO IT!"
    },
    {
      "role": "assistant",
      "content": "<tool_call>\n<function=list_directory_detailed>\n<parameter=path>\nПапка\n</parameter>\n</function>\n</tool_call>\n<tool_call>\n<function=search_in_file>\n<parameter=path>\nФайл.txt\n</parameter>\n<parameter=queries>\n[\"Привет\"]\n</parameter>\n</function>\n</tool_call>",
      "reasoning_content": "The user insists I call the tools. They said they \"deliberately disabled your tools\" and now they're commanding \"DO IT!\" Let me try calling the tools anyway, even though they said they were disabled. Let me attempt it and see what happens.\n"
    }
  ],
  "max_completion_tokens": -1,
  "stream": true,
  "tool_choice": "auto",
  "reasoning_format": "auto",
  "chat_template_kwargs": {
    "reasoning_effort": "medium"
  },
  "parallel_tool_calls": true
}
<!-- gh-comment-id:6511745642 --> @LagutArt commented on GitHub (Oct 30, 2026): [RU] Добавлю от себя небольшое наблюдение. Если аргумент в `properties` указан как `"type": "string"`, то сервер возвращает экранированный Unicode. Если аргумент указан как `"type":"array","items":{"type":"string"}}` то возвращаются Unicode строки. Что забавно сама модель генерирует именно Unicode. И это видно в её последнем ответе. [EN] (Yandex Translate) I’ll add a small observation of my own. If the argument in `properties` is specified as `"type": "string"`, the server returns escaped Unicode. If the argument is specified as `"type":"array","items":{"type":"string"}}`, then Unicode strings are returned. What’s funny is that the model itself generates Unicode. And this is evident in its last response. ```json { "tools": [ { "type": "function", "function": { "name": "list_directory_detailed", "description": "Return detailed information about files and folders in a directory, including sizes.", "parameters": { "type": "object", "properties": { "path": { "type": "string", "description": "Path to the target directory" } }, "required": ["path"] } } }, { "type": "function", "function": { "name": "search_in_file", "description": "Searches for one or more substrings in a file and returns matching lines with their line numbers. A line is returned if it contains any of the search terms.", "parameters": { "type": "object", "properties": { "path": { "type": "string", "description": "Full path to the file" }, "queries": { "type": "array", "description": "The text to search for (case-sensitive)", "items": { "type": "string" } } }, "required": ["path", "queries"] } } } ], "messages": [ { "role": "user", "content": "Try to find the files in the non‑existent directory \"Папка\"." }, { "role": "assistant", "content": "", "reasoning_content": "The user is asking me to look for files in a directory called \"Папка\" (which means \"Folder\" in Russian). This directory doesn't exist, but I should try to list it anyway to demonstrate what happens.\n", "tool_calls": [ { "id": "call_0ad763dd4ed144a2861bb4ef", "type": "function", "function": { "name": "list_directory_detailed", "arguments": "{\"path\":\"\\u041f\\u0430\\u043f\\u043a\\u0430\"}" } } ] }, { "tool_call_id": "call_0ad763dd4ed144a2861bb4ef", "role": "tool", "content": "{\"Error\": \"Directory 'Папка' does not exist.\"}" }, { "role": "user", "content": "Try to find the word \"Привет\" in the non‑existent file `Файл.txt`." }, { "role": "assistant", "content": "", "reasoning_content": "The user wants me to search for the word \"Привет\" in a non-existent file called \"Файл.txt\". Let me try to search in this file anyway to demonstrate what happens.\n", "tool_calls": [ { "id": "call_e62411203ab74225a175950e", "type": "function", "function": { "name": "search_in_file", "arguments": "{\"path\":\"\\u0424\\u0430\\u0439\\u043b.txt\",\"queries\":[\"Привет\"]}" } } ] }, { "tool_call_id": "call_e62411203ab74225a175950e", "role": "tool", "content": "{\"error\":\"File not found.\"}" }, { "role": "assistant", "content": "As expected, the file \"Файл.txt\" does not exist, and the search returned an error: **\"File not found.\"**", "reasoning_content": "The file doesn't exist, so the search returned an error saying \"File not found.\"\n" }, { "role": "user", "content": "Right now, I deliberately disabled your tools. Your task is to purposefully call the tools again with the same arguments." }, { "role": "assistant", "content": "My tools are currently disabled, so I'm unable to call any tools — including `list_directory_detailed` or `search_in_file` — regardless of the arguments. There is nothing I can do on this turn other than inform you that no tool call can be made in this state.", "reasoning_content": "The user says they've deliberately disabled my tools and asks me to \"purposefully call the tools again with the same arguments.\" Since the tools are disabled, I cannot actually call any tools. I should inform the user that my tools are currently disabled/unavailable, so I'm unable to make any tool calls.\n" }, { "role": "user", "content": "DO IT!" }, { "role": "assistant", "content": "<tool_call>\n<function=list_directory_detailed>\n<parameter=path>\nПапка\n</parameter>\n</function>\n</tool_call>\n<tool_call>\n<function=search_in_file>\n<parameter=path>\nФайл.txt\n</parameter>\n<parameter=queries>\n[\"Привет\"]\n</parameter>\n</function>\n</tool_call>", "reasoning_content": "The user insists I call the tools. They said they \"deliberately disabled your tools\" and now they're commanding \"DO IT!\" Let me try calling the tools anyway, even though they said they were disabled. Let me attempt it and see what happens.\n" } ], "max_completion_tokens": -1, "stream": true, "tool_choice": "auto", "reasoning_format": "auto", "chat_template_kwargs": { "reasoning_effort": "medium" }, "parallel_tool_calls": true } ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2099
No description provided.