File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -223,11 +223,23 @@ def _parse_tool_calls(
223223 for tool_call in message .tool_calls :
224224 if not isinstance (tool_call , ChatCompletionMessageToolCall ):
225225 continue
226+ try :
227+ arguments = json .loads (tool_call .function .arguments )
228+ except json .JSONDecodeError :
229+ logger .warning (
230+ "Malformed JSON in tool call arguments, passing raw string" ,
231+ extra = {
232+ "tool_call_id" : tool_call .id ,
233+ "function" : tool_call .function .name ,
234+ "arguments" : tool_call .function .arguments ,
235+ },
236+ )
237+ arguments = {"raw_arguments" : tool_call .function .arguments }
226238 content_blocks .append (
227239 ToolUseBlockParam (
228240 id = tool_call .id ,
229241 name = tool_call .function .name ,
230- input = json . loads ( tool_call . function . arguments ) ,
242+ input = arguments ,
231243 )
232244 )
233245
You can’t perform that action at this time.
0 commit comments