AnthropicPromptCachingMiddleware silently drops string content blocks in system messages
The middleware replaces a trailing string in system message content with a cache_control-only dict, losing the original text.

Framework
Reports that share this framework, grouped in one feed.
The middleware replaces a trailing string in system message content with a cache_control-only dict, losing the original text.
ChatAnthropic in langchain-anthropic 1.6.1 sends top_k=10 to claude-opus-5, which Anthropic has deprecated for Opus 4.7 and later, resulting in a 400 BadRequestError. The client should validate locally and reject unsupported parameters before making a network request.
ChatAnthropic allows forced tool_choice and thinking={"type":"disabled"} to reach the Anthropic API for claude-opus-5-5, causing 400 invalid-request errors. bind_tools(), call-time kwargs, model_kwargs, and create_agent() with structured-output tools are affected.
ChatAnthropic incorrectly routes the documented browser_toolset_20260801 client toolset through JSON-schema conversion, raising ValueError. Non-null toolset_name on tool_use blocks is lost in multi-turn requests, and ordinary tool calls expose toolset_name=None.
When using Anthropic's compaction beta with LangChain agents, invoking with print_mode="messages" or streaming with stream_mode="messages" causes a BadRequestError because the message content includes an unsupported 'index' field in compaction blocks.
The filesystem middleware reads and writes files using the system's locale encoding instead of UTF-8. On Windows and other non-UTF-8 locales, non-ASCII content such as accents or CJK characters raises UnicodeEncodeError/UnicodeDecodeError or silently writes files in a non-UTF-8 encoding, breaking interoperability and causing tool call failures.
ChatAnthropic._assert_valid_model_configuration() only rejects manual thinking for models starting with claude-opus-5. Anthropic also rejects manual thinking for claude-opus-4-7, claude-opus-4-8, and claude-sonnet-5, so LangChain forwards invalid requests and the API returns HTTP 400.
ChatAnthropic's message serialization for SystemMessage does not preserve additional_kwargs such as output_config and clear_at. This causes per-message effort changes to be silently ignored and turn-scoped instructions to become persistent across later turns. Claude Sonnet 5.5 is also not recognized by the message-level system message capability check.
LangChain agent using Anthropic's web_search_20260209 tool intermittently fails with a 400 error because the request payload includes a code_execution tool_use without a corresponding code_execution_tool_result. This occurs when web_search triggers automatic code_execution and LangChain's message handling drops the tool result.
On Windows, path validation in FilesystemClaudeTextEditorMiddleware and FilesystemClaudeMemoryMiddleware rejects valid nested virtual paths due to backslash vs forward slash mismatch in allowed_prefixes comparison.
In langchain-anthropic's _format_messages, when an AIMessage contains both a tool_use content block and a matching tool_call in the structured tool_calls field, the tool_use block is rebuilt from tool_calls and any extra keys on the original block, notably cache_control, are discarded. This causes prompt-cache breakpoints placed on tool_use blocks to be silently lost.
ChatAnthropic.bind_tools() warns and removes forced tool_choice when thinking is set on the constructor, but the same thinking supplied via invoke() is not checked. This sends an invalid combination (thinking enabled + tool_choice={'type':'any'}) to Anthropic API, resulting in HTTP 400.