Skip to content

fix: route malformed tool-call arguments to bad_json instead of crashing the loop - #818

Open
Xperiamol wants to merge 1 commit into
lsdefine:mainfrom
Xperiamol:fix/malformed-tool-args
Open

Xperiamol wants to merge 1 commit into
lsdefine:mainfrom
Xperiamol:fix/malformed-tool-args

Conversation

@Xperiamol

Copy link
Copy Markdown

agent_runner_loop calls json.loads(tc.function.arguments) unguarded. With the text tool protocol, a model emitting "arguments": "not json" raises JSONDecodeError, and "arguments": "[1,2,3]" raises AttributeError at args['_index'] - either aborts the whole run instead of reaching the existing bad_json self-correction path.

parse_tool_call now maps unparsable / non-object arguments to bad_json, so the error goes back to the model. Valid calls are unchanged.

model reply arguments before after
"not json at all" JSONDecodeError bad_json fed back, run continues
"[1,2,3]" AttributeError bad_json fed back, run continues
{"script":"print(1)"} runs runs

Net +6 lines.

…ing the loop

agent_runner_loop called json.loads(tc.function.arguments) unguarded. With the
text tool protocol, a model emitting `"arguments": "not json"` raised
JSONDecodeError, and `"arguments": "[1,2,3]"` raised AttributeError on
args['_index'] - both abort the whole run.

parse_tool_call now maps non-object / unparsable arguments to the existing
bad_json tool, so the error is fed back to the model for self-correction.
@Xperiamol
Xperiamol force-pushed the fix/malformed-tool-args branch from 5c826d3 to fc8d084 Compare September 29, 2026 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant