[Bugfix] accept redacted thinking blocks in Anthropic messages (#36992)

Signed-off-by: Benjamin Bartels <benjaminba@tiglab-ubuntu.ilab.local>
Signed-off-by: bbartels <benjamin@bartels.dev>
Co-authored-by: Benjamin Bartels <benjaminba@tiglab-ubuntu.ilab.local>
This commit is contained in:
Benjamin Bartels
2026-03-16 14:01:57 +00:00
committed by GitHub
parent 04bf5a35fa
commit 0e5a9382af
3 changed files with 278 additions and 1 deletions

View File

@@ -34,7 +34,14 @@ class AnthropicUsage(BaseModel):
class AnthropicContentBlock(BaseModel):
"""Content block in message"""
type: Literal["text", "image", "tool_use", "tool_result", "thinking"]
type: Literal[
"text",
"image",
"tool_use",
"tool_result",
"thinking",
"redacted_thinking",
]
text: str | None = None
# For image content
source: dict[str, Any] | None = None
@@ -48,6 +55,8 @@ class AnthropicContentBlock(BaseModel):
# For thinking content
thinking: str | None = None
signature: str | None = None
# For redacted thinking content (safety-filtered by the API)
data: str | None = None
class AnthropicMessage(BaseModel):

View File

@@ -224,6 +224,12 @@ class AnthropicServingMessages(OpenAIServingChat):
content_parts.append({"type": "image_url", "image_url": {"url": image_url}})
elif block.type == "thinking" and block.thinking is not None:
reasoning_parts.append(block.thinking)
elif block.type == "redacted_thinking":
# Redacted thinking blocks contain safety-filtered reasoning.
# We skip them as the content is opaque (base64 'data' field),
# but accepting the block prevents a validation error when the
# client echoes back the full assistant message.
pass
elif block.type == "tool_use":
cls._convert_tool_use_block(block, tool_calls)
elif block.type == "tool_result":