From ae0743ec3b0428bd3aaac66b067b2e437b2dca36 Mon Sep 17 00:00:00 2001 From: ccurme Date: Fri, 17 Apr 2026 10:23:11 -0400 Subject: [PATCH] fix(anthropic): strip null encrypted_content from compaction blocks (#36850) --- libs/partners/anthropic/langchain_anthropic/chat_models.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libs/partners/anthropic/langchain_anthropic/chat_models.py b/libs/partners/anthropic/langchain_anthropic/chat_models.py index 1beba466a3b..380f0671422 100644 --- a/libs/partners/anthropic/langchain_anthropic/chat_models.py +++ b/libs/partners/anthropic/langchain_anthropic/chat_models.py @@ -1454,6 +1454,11 @@ class ChatAnthropic(BaseChatModel): content_block = event.delta.model_dump() content_block["index"] = event.index content_block["type"] = "compaction" + if ( + "encrypted_content" in content_block + and content_block["encrypted_content"] is None + ): + content_block.pop("encrypted_content") message_chunk = AIMessageChunk(content=[content_block]) # Process final usage metadata and completion info @@ -1501,6 +1506,8 @@ class ChatAnthropic(BaseChatModel): block.pop("citations") if "caller" in block and block["caller"] is None: block.pop("caller") + if "encrypted_content" in block and block["encrypted_content"] is None: + block.pop("encrypted_content") if ( block.get("type") == "thinking" and "text" in block