@@ -127,7 +127,20 @@ static const ParametersTypeMap_t parseToolSchema(const std::string& functionName
127127 return result;
128128}
129129
130- // helper function to escape \n, "
130+ static std::string escapeQuotes (const std::string& input) {
131+ std::string output;
132+ output.reserve (input.size ());
133+ for (char c : input) {
134+ switch (c) {
135+ case ' "' :
136+ output += " \\\" " ;
137+ break ;
138+ default :
139+ output += c;
140+ }
141+ }
142+ return output;
143+ }
131144static std::string escapeString (const std::string& input) {
132145 std::string output;
133146 output.reserve (input.size ());
@@ -136,9 +149,6 @@ static std::string escapeString(const std::string& input) {
136149 case ' \n ' :
137150 output += " \\ n" ;
138151 break ;
139- case ' "' :
140- output += " \\\" " ;
141- break ;
142152 default :
143153 output += c;
144154 }
@@ -153,7 +163,7 @@ static std::string setCorrectValueType(std::string& inputValue, const std::strin
153163 return inputValue;
154164 }
155165 if (paramIt->second == ParameterType::STRING) {
156- inputValue = " \" " + inputValue + " \" " ;
166+ inputValue = " \" " + escapeQuotes ( inputValue) + " \" " ;
157167 return inputValue;
158168 }
159169 if (paramIt->second == ParameterType::BOOLEAN) {
@@ -240,8 +250,8 @@ bool Qwen3CoderToolParserImpl::parseUntilStateChange(ToolCalls_t& toolCalls) {
240250 SPDLOG_DEBUG (" Tool schema not found for tool: {}, leaving parameter: {} as string" , this ->currentFunction .name , this ->currentParameterName );
241251 } else {
242252 // we don't want to escape entry/exit " for string parameters
243- auto escaped = escapeString (parameterValue);
244- parameterValue = setCorrectValueType (escaped , this ->currentParameterName , paramIt->second );
253+ // auto escaped = escapeString(parameterValue);
254+ parameterValue = escapeString ( setCorrectValueType (parameterValue , this ->currentParameterName , paramIt->second ) );
245255 }
246256 auto res = this ->currentFunction .parameters .try_emplace (this ->currentParameterName , parameterValue);
247257 if (!res.second )
@@ -361,6 +371,7 @@ std::optional<rapidjson::Document> Qwen3CoderToolParser::sendFullDelta(std::opti
361371 // now we need to add string toolCall.arguments to argumentsWrapper under "arguments" key
362372 rapidjson::Value toolCallsString (rapidjson::kStringType );
363373 toolCallsString.SetString (toolCall.arguments .c_str (), allocator);
374+ SPDLOG_TRACE (" Tool call arguments string: {}" , toolCall.arguments );
364375 argumentsWrapper.AddMember (" arguments" , toolCallsString, allocator);
365376 auto currentDelta = wrapDelta (argumentsWrapper, this ->toolCallIndex );
366377 SPDLOG_DEBUG (" First delta doc: {}" , documentToString (currentDelta));
0 commit comments