Repository navigation
Description
Describe the bug
Summary
When the model returns a tool call that is present but malformed (wrong tool name, missing command, or complete-but-invalid JSON arguments), the correction message sent back to the model is the "your previous response was cut off due to the output token limit" prompt, and the real error (e.g. Unknown tool 'shell'.) is never shown to the model. This can cause the model to keep retrying in the wrong direction until it hits max_consecutive_format_errors and exits with RepeatedFormatError.
Affected version
v2.4.4 (and likely earlier).
Where
Parser passes finish_reason into the error template:
src/minisweagent/models/utils/actions_toolcall.py(parse_toolcall_actions)src/minisweagent/models/litellm_model.py→template_kwargs={"finish_reason": response.choices[0].finish_reason}
Templates that contain the problematic branch (finish_reason in ["length", "tool_calls"]):
src/minisweagent/config/mini.yaml:130src/minisweagent/config/benchmarks/swebench.yaml:160src/minisweagent/config/benchmarks/programbench.yaml:260src/minisweagent/config/default.yaml:145(text-based)src/minisweagent/config/mini_textbased.yaml:146(text-based)src/minisweagent/config/benchmarks/swebench_backticks.yaml:219(text-based)src/minisweagent/config/benchmarks/swebench_xml.yaml:204(text-based)
The tool-call configs (mini.yaml, swebench.yaml, programbench.yaml) are the ones actually affected, because only tool-call responses produce finish_reason == "tool_calls". The text-based configs carry the same branch but are not hit in practice (they do not use tools).
The template branch in question
{% if finish_reason is defined and finish_reason in ["length", "tool_calls"] -%}
Your previous response reached the output token limit (finish_reason={{ finish_reason }}) before you produced a tool call, so it was cut off. Respond more concisely and finish with exactly one bash tool call. If you need to think more, do so briefly.
{%- else -%}
Tool call error:
<error>
{{error}}
</error>
...
{%- endif %}Root cause
The condition treats "length" (a genuine truncation) and "tool_calls" (a normal completion that produced tool calls) identically. When a model produces a tool call and finishes normally, providers return finish_reason == "tool_calls". If that tool call fails validation in parse_toolcall_actions (unknown tool name, missing command, or invalid-but-complete JSON), a FormatError is raised — but because finish_reason == "tool_calls", the template renders the truncation message instead of {{ error }}. The actual validation error is discarded from the model's view.
Steps to reproduce
Have the model emit a tool call with a wrong tool name, e.g.:
{
"role": "assistant",
"content": "Let me look at the directory.",
"tool_calls": [
{"id": "call_x", "type": "function",
"function": {"name": "shell", "arguments": "{\"command\": \"ls\"}"}}
]
}Here finish_reason == "tool_calls".
Expected correction message to the model:
Tool call error:
<error>
Unknown tool 'shell'.
</error>
...guidance on how to call the bash tool...
Actual correction message to the model:
Your previous response reached the output token limit (finish_reason=tool_calls) before you produced a tool call, so it was cut off. Respond more concisely and finish with exactly one bash tool call. If you need to think more, do so briefly.
The Unknown tool 'shell'. error is never surfaced.
Activity
klieret commentedon Jul 6, 2026
thanks for raising this, this should indeed be fixed
Batman0x0000001 commentedon Jul 6, 2026
Hi, I’d like to try working on this issue.
My understanding is that
finish_reason == "tool_calls"should not be treated as an output truncation case. I plan to make a small fix by narrowing the affectedformat_error_templatechecks to only handlefinish_reason == "length", and add a focused regression test for malformed tool calls withfinish_reason == "tool_calls".Please let me know if this direction sounds reasonable.
fix(models): don't mask malformed tool-call errors as truncation (SWE…