Fix Claude API "thinking blocks cannot be modified" 400
Claude API 400 thinking or redacted_thinking blocks cannot be modified means the last assistant turn was altered. Send its content back exactly as received.
`thinking` or `redacted_thinking` blocks in the latest assistant message cannot be modified. These blocks must remain as they were in the original response.When you send a tool_result in a tool-use loop, the thinking or redacted_thinking blocks in the preceding assistant message did not match what the API returned, so the request was rejected (400 invalid_request_error). The usual cause is code that filters response blocks by type and drops redacted_thinking or a thinking block with empty text. Send the assistant turn's content back untouched and the error goes away.
[1] Read the position at the start of the message. The error starts with the location of the offending block, such as messages.1.content.0. Check that this index in your messages array is the last assistant message and which block inside it is named; that narrows down where it changed.
[2] Find the code that filters blocks by type. The official docs name two typical mistakes.
- A filter that keeps only
block.type == "thinking".redacted_thinkingis a separate type and silently drops out. The API returns that block when reasoning is redacted for safety. - Code that rebuilds the assistant message from the text and tool calls instead of reusing the response.
Check one more thing. Recent models such as Claude Opus 5.5, Sonnet 5.5 and Haiku 5.5 default to display: "omitted", so thinking blocks arrive with an empty thinking field. A cleanup step that "drops empty blocks" removes them and causes the same error.
[3] Fix it to send back exactly what you received. The rules:
| Case | Rule (official docs) |
|---|---|
| Within a tool-use turn | Thinking blocks must be passed back |
| Across turns | Passing everything back is recommended (the API filters as needed) |
| Earlier turns outside tool use | Thinking may be omitted |
| Inside the last assistant message | Consecutive thinking blocks cannot be reordered, edited or partially dropped (redacted_thinking included) |
With an SDK, put the response object's content into the assistant message as is, then add the user message that carries the tool_result. Don't reassemble the blocks. To trim old thinking, don't delete it yourself; use the clear_thinking_20251015 context-editing strategy.
[4] Check before sending. Below, a function compares the thinking-type blocks of the last assistant message with the original, run against a sample response (a signed thinking, a redacted_thinking, an empty thinking, and a tool_use). No API call was made.
$ python3 check_thinking.pybuggy filter: count 1 != 3echo as received: OKreordered: block 0 differs: sent redacted_thinking vs original thinking; block 1 differs: sent thinking vs original redacted_thinkingedited text: block 0 differs: sent thinking vs original thinkingbuggy filter keeps only "thinking with text, plus tool_use", leaving one of three blocks. Only the echo-as-received case passed; swapping the order or changing one character was caught too. The comparison matches blocks as key-sorted JSON, so a changed signature or data is caught as well. The core of the check:
import json THINKING_TYPES = ("thinking", "redacted_thinking") def thinking_blocks(content): return [b for b in content if b.get("type") in THINKING_TYPES] def check_last_assistant(messages, original_content): """Return a list of problems; empty means the thinking blocks match.""" last = [m for m in messages if m["role"] == "assistant"][-1] sent = thinking_blocks(last["content"]) want = thinking_blocks(original_content) problems = [] if len(sent) != len(want): problems.append(f"count {len(sent)} != {len(want)}") for i, (s, w) in enumerate(zip(sent, want)): if json.dumps(s, sort_keys=True) != json.dumps(w, sort_keys=True): problems.append(f"block {i} differs: sent {s.get('type')} vs original {w.get('type')}") return problems[5] Re-sending the same body gives the same result. Retries do not help; the code has to change.
A similar but different error: Invalid signature in thinking block. The block is bound to a different conversation. means the conversation before the block (system, tools, earlier messages) changed; see Invalid signature in thinking block fix. For a 400 where the thinking setting itself does not fit the model, see thinking.type.enabled fix.