Skip to content

What does an AI agent do with a tool call the model never finished?

Unity Horizon7 min read

It runs it. A tool call cut off by the token limit is repaired into valid JSON before your code sees it, and three common repairers disagree on the arguments.

It runs it. A tool call the token limit cut in half does not arrive as an error. The fragments that got through are repaired into valid JSON before your code sees them, so the call reaches the tool looking finished. We put the same six cut-off buffers through the three partial-JSON parsers most agents depend on. Three parsers, three different sets of arguments. Checked by Unity Horizon on 27 November 2026.

How does a tool call get cut off in the middle?

The model writes a tool call one token at a time. max_tokens counts those tokens like any others. Anthropic documents the case in a collapsed accordion on its stop reasons page: "If Claude's response is cut off because it hit the max_tokens limit, and the truncated response contains an incomplete tool use block, you'll need to retry the request with a higher max_tokens value to get the full tool use." That is the official guidance in full.

The response is an HTTP 200 and the turn looks ordinary. One field differs. stop_reason reads max_tokens where a finished call would read tool_use. A second value on the same page, model_context_window_exceeded, cuts a call the same way when the window runs out instead of your limit, and the instruction printed next to it is to "treat the response as truncated".

Agents stream. The SDKs refuse a non-streaming call above max_tokens 21,333, which we read out of their source in Which timeout fires first when an AI model thinks for five minutes?. On the streaming path the arguments arrive as input_json_delta fragments. Something in your stack then has to turn an unfinished fragment stream into a dict.

What is in the arguments after the cut?

Whatever your parser decides. The parsers disagree. The Anthropic Python SDK accumulates the fragments and calls jiter.from_json(json_buf, partial_mode=True), at line 509 of anthropic 2.14.0. The TypeScript SDK hands the buffer to a vendored parser whose own comment says it "drops a partial trailing token, closes open brackets". langchain-core accumulates the fragments itself and calls parse_partial_json. That one closes an unterminated string by appending a quote. The repair is a byte buffer, a parser nobody on your team chose, a closing brace appended on its behalf, and a dict that validates.

Method, repeatable in a minute: six truncated buffers, one call into each parser, the return value read off. anthropic 2.14.0 with jiter 0.19.0, @anthropic-ai/sdk 1.14.0 and langchain-core 1.8.5, run 27 November 2026.

Cut-off buffer anthropic 2.14.0 @anthropic-ai/sdk 1.14.0 langchain-core 1.8.5
{"to": "ops@x.com", "subject": "Invoice 4471", "body": "Please pa body dropped body dropped "body": "Please pa"
{"command": "rm -rf build/tmp", "args": ["--keep", "src", "te ["--keep", "src"] ["--keep", "src"] ["--keep", "src", "te"]
{"amount": 1200 {"amount": 1200} {} {"amount": 1200}
{"ids": [1, 2, 3 {"ids": [1, 2, 3]} {"ids": [1, 2]} {"ids": [1, 2, 3]}
{"limit": 100, "offset": 2 both fields kept {"limit": 100} both fields kept
{"dry_run": tru {} {} {}

Read the amount row twice. That buffer is 12000 cut after the fourth digit, and two of the three parsers hand the tool 1200: right type, field present, wrong by a factor of ten. The TypeScript SDK throws that token away, because its tokenizer marks a number running to the end of the buffer unterminated. One vendor, two official SDKs, two answers from the same bytes.

A cut-off string looks wrong. A cut-off number looks fine.

Does anything refuse to run a cut-off tool call?

One layer out of the eight we read. pydantic-ai raises IncompleteToolCall when the finish reason is length, the last part of the response is a tool call, and its arguments are empty or will not parse. On the streaming path the raw fragment string gives it exactly that. The other seven either run the repaired call or make it disappear.

Layer, read 27 November 2026 What it does with a tool call the token limit cut off
pydantic-ai Refuses, raising IncompleteToolCall. The only guard we found
LangGraph ToolNode Runs it. The file holds no reference to stop_reason, finish_reason or response_metadata
langchain-core Repairs the arguments, and a repaired dict becomes a valid tool_call rather than an invalid_tool_call
Agno Collects tool calls only when stop_reason == "tool_use", so the call disappears and the turn reads as answered
CrewAI Strict json.loads on the accumulated arguments and continue on JSONDecodeError, so the call is skipped with no error raised
LiteLLM Forwards the raw fragments as an OpenAI-shaped arguments string and maps the stop reason to length
llama-index get_tool_calls_from_response filters the tool use blocks and never reads the stop reason
Vercel AI SDK Its length check applies only to a step with no client tool calls. Otherwise the call is parsed and validated against the tool schema

Refuse, run, vanish. Only the first was decided by anyone. Vanishing is the hardest of them to find afterwards: the transcript shows a turn that produced no tool call, and the loop moves on. Agno's tracker has carried that one since 26 January 2026 as Claude Max Tokens error, return empty response, still open. Two other projects shipped their own patch for it, an evaluation project on 14 October and a gateway on 4 November. The gateway's issue describes what arrives as a call that "looks like a valid, complete call".

Why does validating the arguments not catch it?

Because the value that survives is the right type. OpenAI's chat reference warns that the model "does not always generate valid JSON", that it may "hallucinate parameters not defined by your function schema", and that you should "Validate the arguments in your code before calling your function". Schema validation does catch half of this. A dropped body fails a required-field check, and the call is rejected before the tool runs.

It passes 1200 without a complaint. The field is present, the type is right, and no schema knows the model was mid-digit when the limit landed.

The check that catches a short number sits one layer up. A read before every write, which is the argument we made in How do you stop an AI agent from doing the same thing twice?, compares the argument against the record about to change, and a payment of 1200 against an invoice of 12000 fails that comparison. We built OFFSET, which files declarations directly to the ΑΑΔΕ portal, and a write tool on a filing agent is where a short argument stops being a curiosity.

Who pays for this, and who never notices?

Agents that read pay close to nothing. A search runs with a truncated query. It returns the wrong rows, the next model call reads them, and the step corrects itself. That is how the behaviour survives months of demos with nobody seeing it. Retrieval forgives a missing word.

The bill lands on agents that write. The email whose body is "Please pa". The file written with half its contents. The delete that got two of the three ids. The rm -rf whose argument list lost its last entry, or kept "te" instead. Those teams hear about it from the recipient, not from the logs, because the repair leaves no record that anything was repaired.

The split between frameworks runs the same way. A team on the one framework that checks is covered by a maintainer's decision it never read. A team running its own loop owns the check. An agent loop is thirty lines, so it is usually the first code written and the last code revisited.

What do you change on Monday?

Read the stop reason before you dispatch. If it is max_tokens or model_context_window_exceeded and the last content block is a tool use block, do not run that block.

Then hand the refusal back to the model as a tool result instead of resending the request at a higher limit. Anthropic's own example resends messages with a larger max_tokens and does not append the truncated turn, so a prompt that reliably overruns its limit asks the same question twice and pays twice for the privilege. The second run overruns as well.

And log the stop reason on every step, next to the model and the tool name. An agent that has never logged it cannot tell you whether this happens weekly or hourly, and the repair guarantees there is nothing else in the record to count.

The six buffers are ours. We wrote them to look like arguments an agent would write, so the parser behaviour above is measured and the shape of the input is assumed. We have not captured a real max_tokens turn with a half-written tool_use in it. The engineer who published the closest thing to a fix says the same about that patch: "I have not checked what a real non-streamed max_tokens response puts in a cut-off tool_use." If you have one captured, we would like the bytes.

If you are scoping an agent whose tools write rather than read, our agentic AI systems page sets out how we scope one. Which of your agent's tools would do something irreversible with one argument missing?

Common questions

What happens when an AI model hits max_tokens in the middle of a tool call?

The response comes back as an HTTP 200 carrying an incomplete tool use block, with stop_reason set to max_tokens instead of tool_use. Anthropic's guidance is to retry the request with a higher max_tokens value to get the full tool use. Nothing in the response marks the block itself as unfinished, so a loop that does not read the stop reason cannot tell the difference.

Does the Anthropic SDK tell you a tool call was truncated?

No. On the streaming path the Python SDK repairs the partial arguments with jiter.from_json in partial mode and the TypeScript SDK uses a vendored partial-JSON parser, and both hand back a well-formed input dict with no flag on it. The only signal is the stop_reason field on the message.

Does validating tool arguments against a JSON schema catch a truncated call?

Only sometimes. A string cut off mid-value is dropped by both Anthropic SDKs, so a required field fails validation and the call is rejected. A number cut off mid-digits keeps the digits that arrived, so 12000 truncated after the fourth digit arrives as 1200, which is the right type and present, so it clears every schema check.

How do you stop an AI agent from running a truncated tool call?

Read the stop reason before dispatching. If it is max_tokens or model_context_window_exceeded and the last content block is a tool use block, refuse the call and return that refusal to the model as a tool result so it can re-issue the call. Of eight agent layers we read on 27 November 2026, only pydantic-ai does this on its own.

What is the difference between stop_reason max_tokens and model_context_window_exceeded?

max_tokens means the response reached the limit set in the request. model_context_window_exceeded means the response filled the model's context window. Anthropic's stop reason table says to raise the limit or continue the response in the first case and to treat the response as truncated in the second. Both can land in the middle of a tool call.