Skip to content

Your lightweight open-source personal agent.

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

04cb5fe57f8afa39
diff --git a/nanobot/providers/anthropic_provider.py b/nanobot/providers/anthropic_provider.py
index 31f2bc2f1..504c35ad0 100644
--- a/nanobot/providers/anthropic_provider.py
+++ b/nanobot/providers/anthropic_provider.py
@@ -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)"