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.

Tech tag
Published reports that match this technical term, gathered from the local catalog.
The middleware replaces a trailing string in system message content with a cache_control-only dict, losing the original text.
ChatAnthropic ignores the metadata provided in the invoke config, so the user_id is not sent to the Anthropic API. This prevents prompt caching from working when connecting to third-party agents that require user_id for cache partitioning. The issue can be reproduced by invoking the model with a config containing metadata and observing that the request payload lacks the metadata field.
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.