fix(providers): coerce typeless Anthropic content blocks to text (#3993)

This commit is contained in:
04cb 2026-05-29 22:06:43 +08:00 committed by Xubin Ren
parent 288146315e
commit 5fe57f8afa

View File

@ -228,6 +228,13 @@ class AnthropicProvider(LLMProvider):
if converted:
result.append(converted)
continue
if not item.get("type"):
# Anthropic requires every content block to declare a "type".
# A tool that returned a bare dict (or a list of dicts) lands
# here; coerce it to a text block instead of emitting a block
# the API rejects with "content.0.type: Field required".
result.append({"type": "text", "text": str(item)})
continue
result.append(item)
return result or "(empty)"