From f36fcfb82559ed3ca4ac7060df9f2b680c28d595 Mon Sep 17 00:00:00 2001 From: yurekami Date: Thu, 12 Feb 2026 20:06:51 +0900 Subject: [PATCH] templates : fix double-escaping in gpt-oss tool call arguments and responses When tool_call.arguments is already a JSON string (as sent by the OpenAI API), applying |tojson wraps it in quotes and escapes internal quotes, producing double-escaped output like "{\"key\":\"val\"}" instead of {"key":"val"}. Add an `is string` guard (same pattern used by Hermes, Qwen3 templates) so arguments are output as-is when already a string, and only serialized via tojson when they are a dict/object. Similarly, remove |tojson from tool response message.content which is always a string from the API. Fixes #19520 --- models/templates/openai-gpt-oss-120b.jinja | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/models/templates/openai-gpt-oss-120b.jinja b/models/templates/openai-gpt-oss-120b.jinja index dc7bb11927..a13a85779f 100644 --- a/models/templates/openai-gpt-oss-120b.jinja +++ b/models/templates/openai-gpt-oss-120b.jinja @@ -296,7 +296,11 @@ {{- "<|start|>assistant to=" }} {{- "functions." + tool_call.name + "<|channel|>commentary " }} {{- (tool_call.content_type if tool_call.content_type is defined else "json") + "<|message|>" }} - {{- tool_call.arguments|tojson }} + {%- if tool_call.arguments is string -%} + {{- tool_call.arguments }} + {%- else -%} + {{- tool_call.arguments | tojson }} + {%- endif -%} {{- "<|call|>" }} {%- set last_tool_call.name = tool_call.name %} {%- elif loop.last and not add_generation_prompt %} @@ -319,7 +323,7 @@ {{- raise_exception("Message has tool role, but there was no previous assistant message with a tool call!") }} {%- endif %} {{- "<|start|>functions." + last_tool_call.name }} - {{- " to=assistant<|channel|>commentary<|message|>" + message.content|tojson + "<|end|>" }} + {{- " to=assistant<|channel|>commentary<|message|>" + message.content + "<|end|>" }} {%- elif message.role == 'user' -%} {{- "<|start|>user<|message|>" + message.content + "<|end|>" }} {%- endif -%}