Fix LLM response truncation when hitting maximum output token limit
Discord Message
Author: tusharjain9104 Channel: #shelley Link: https://discord.com/channels/1405685085923049482/1450334528210993295/1457884388938219763
I had Shelley debug the log file 🙂 . Here is what it came back with:
Found it. Here's what happened:
Summary of the failure:
-
At 23:21:33 - A bash tool executed successfully (message_count=109 shows it was deep into a conversation loop)
-
At 23:22:49 - About 1 minute and 16 seconds into the next LLM request, the response hit a limit and triggered:
anthropic_retrying_with_larger_tokens- meaning the initial max_tokens setting wasn't enough -
There was a ~30 second retry sleep, then the request was retried with a larger token limit (16384)
-
At 23:24:37 - After ~3 minutes total (184 seconds), the LLM returned with:
output_tokens=16384stop_reason=StopReasonMaxTokens
This means the model hit the maximum output token limit (16k) and the response was truncated.
-
The response had
content_count=2andend_of_turn=true- but the stop reason being MaxTokens means the model was in the middle of generating something (likely a large patch forstatic/index.html) when it ran out of tokens.
Root cause: The LLM tried to output the complete new static/index.html file in a single patch operation using overwrite, and the file content was so large it exceeded the 16,384 token output limit. The response was truncated mid-stream, leaving the patch operation incomplete.
The conversation technically "finished" (end_of_turn=true was set) but the actual work was incomplete because the patch content was cut off.
This is a known limitation - when generating very large files, the model can hit token limits. The workaround would be to make incremental patches rather than overwriting entire files, or to generate large files in chunks.
1 Comment
Please let me know if this keeps occuring to you!