Raise `IncompleteToolCall` when the token limit cuts off an Anthropic output tool call, instead of retrying
(Comment written by Claude, on Douwe's behalf.)
Follow-up to #13125 (part of #12399).
Why
#13125 made a cut-off output tool call raise IncompleteToolCall after the first request, but it only recognized arguments that don't parse as JSON. Anthropic doesn't send the partial arguments: a tool call cut off at max_tokens comes back with {} as its input, and, when streamed, with no input_json_delta content at all (''). Reproduced with claude-haiku-5-5 and max_tokens=40: stop_reason: max_tokens, last block tool_use with input: {}. Both parse as an empty object, so the run spent its output retries on schema failures (Exceeded maximum output retries (1)), and run_stream() raised Output validation failed during streaming.
Anthropic's docs say a tool_use block at the end of a max_tokens response is incomplete. A tool call with no arguments only reaches this check when its tool requires arguments (otherwise it validates and runs), so treating empty arguments on the last tool call of a 'length' response as cut off doesn't touch complete calls.
New public surface
None.
User-visible behavior
An output tool call that the token limit cut off with no arguments ({}, '' or None) raises IncompleteToolCall after the first request, in run(), iter() and run_stream(), as one with JSON that doesn't parse already does. A function tool call like that raises IncompleteToolCall once its retries are used up, instead of the generic retry-limit UnexpectedModelBehavior (which IncompleteToolCall subclasses). Arguments that parse to a non-empty value keep their retry, as #13125 decided.
Verification
tests/models/test_anthropic.py::test_anthropic_tool_output_cut_off_by_max_tokens(recorded,streamFalse/True; each cassette has one request, and asserts the{}/''args andmax_tokensstop reason)tests/test_agent.py::test_truncated_output_tool_call_raises_without_retrygains{}and''argstests/test_agent.py::test_output_tool_args_that_parse_but_are_rejected_with_finish_reason_length_are_retriedgains a non-empty dict that the schema rejects
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
- PR title is fit for the release changelog.
š¤ Generated with Claude Code
Summary by cubic
Anthropic returns an output tool call the token limit cut off with {} as its input, or no input at all when streamed. This parsed as complete arguments, so the call was retried as a schema failure until the retry budget was used up. Such cut-off calls now raise IncompleteToolCall on the first request, in run(), iter(), and run_stream(), applying only to the tool call the response ends on.
- Arguments that parse to a non-empty value, and empty arguments that are valid for the tool, behave as before.
- Function tool calls with empty arguments keep their retry, raising
IncompleteToolCallonly once the retry budget is used up.