Skip to content

Commit ae0743e

Browse files
authored
fix(anthropic): strip null encrypted_content from compaction blocks (#36850)
1 parent c2fd6a2 commit ae0743e

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

libs/partners/anthropic/langchain_anthropic/chat_models.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,11 @@ def _make_message_chunk_from_anthropic_event(
14541454
content_block = event.delta.model_dump()
14551455
content_block["index"] = event.index
14561456
content_block["type"] = "compaction"
1457+
if (
1458+
"encrypted_content" in content_block
1459+
and content_block["encrypted_content"] is None
1460+
):
1461+
content_block.pop("encrypted_content")
14571462
message_chunk = AIMessageChunk(content=[content_block])
14581463

14591464
# Process final usage metadata and completion info
@@ -1501,6 +1506,8 @@ def _format_output(self, data: Any, **kwargs: Any) -> ChatResult:
15011506
block.pop("citations")
15021507
if "caller" in block and block["caller"] is None:
15031508
block.pop("caller")
1509+
if "encrypted_content" in block and block["encrypted_content"] is None:
1510+
block.pop("encrypted_content")
15041511
if (
15051512
block.get("type") == "thinking"
15061513
and "text" in block

0 commit comments

Comments
 (0)