Skip to content

Your lightweight open-source personal agent.

fix: validate content block type in Anthropic assistant blocks (#4060)

axelray-devefb792ff243f
diff --git a/nanobot/providers/anthropic_provider.py b/nanobot/providers/anthropic_provider.py
index 01c5c30c2..c52600f6b 100644
--- a/nanobot/providers/anthropic_provider.py
+++ b/nanobot/providers/anthropic_provider.py
@@ -275,7 +275,16 @@ class AnthropicProvider(LLMProvider):
blocks.append({"type": "text", "text": content})
elif isinstance(content, list):
for item in content:
- blocks.append(item if isinstance(item, dict) else {"type": "text", "text": str(item)})
+ if isinstance(item, dict):
+ if not item.get("type"):
+ # Anthropic requires every content block to declare a "type".
+ # A tool that returned a bare dict lands here; coerce it to
+ # a text block instead of emitting one that the API rejects.
+ blocks.append({"type": "text", "text": str(item)})
+ else:
+ blocks.append(item)
+ else:
+ blocks.append({"type": "text", "text": str(item)})
for tc in msg.get("tool_calls") or []:
if not isinstance(tc, dict):