From 0e3aad69409352cc4ab6679a4fdf19c2a1b4f789 Mon Sep 17 00:00:00 2001 From: Liz <91279165+lizradway@users.noreply.github.com> Date: Mon, 29 Jun 2026 15:07:50 -0400 Subject: [PATCH] fix: suppress Pydantic serialization warnings for ParsedMessageStopEvent Use TYPE_CHECKING guard on ParsedMessageStopEvent.message field to prevent Pydantic from building a serializer schema that expects ParsedTextBlock[TypeVar] in the content union. At runtime, the unparameterized ParsedMessage avoids the type mismatch that causes PydanticSerializationUnexpectedValue warnings on every streamed response. This follows the same pattern already used for ParsedContentBlockStopEvent.content_block in the same file. --- src/anthropic/lib/streaming/_types.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/anthropic/lib/streaming/_types.py b/src/anthropic/lib/streaming/_types.py index 7399e76f4..8e4a1e404 100644 --- a/src/anthropic/lib/streaming/_types.py +++ b/src/anthropic/lib/streaming/_types.py @@ -110,7 +110,10 @@ class ContentBlockStopEvent(RawContentBlockStopEvent): class ParsedMessageStopEvent(RawMessageStopEvent, GenericModel, Generic[ResponseFormatT]): type: Literal["message_stop"] - message: ParsedMessage[ResponseFormatT] + if TYPE_CHECKING: + message: ParsedMessage[ResponseFormatT] + else: + message: ParsedMessage class ParsedContentBlockStopEvent(RawContentBlockStopEvent, GenericModel, Generic[ResponseFormatT]):