#10246·agno

[Bug] Claude format_messages crashes when tool arguments are null or a dict

Author: MohammadHijjawi97Created Sep 17, 2026Updated Sep 17, 2026

Description

Claude request assembly calls json.loads on tool-call arguments whenever the key is present. JSON null and already-parsed dicts both raise TypeError and abort building the Anthropic request. Gemini already treats those shapes as empty or as a dict.

Steps to Reproduce

  1. Build an assistant message whose tool call has "arguments": None (or a dict).
  2. Call format_messages.
python
from agno.models.message import Message
from agno.utils.models.claude import format_messages

assistant = Message(
    role="assistant",
    content=None,
    tool_calls=[{
        "id": "toolu_1",
        "type": "function",
        "function": {"name": "get_weather", "arguments": None},
    }],
)
format_messages([Message(role="user", content="hi"), assistant])

Expected Behavior

Null arguments become {}. A dict is passed through. Request assembly succeeds.

Actual Behavior

TypeError: the JSON object must be str, bytes or bytearray, not NoneType (or not dict).

Environment

  • OS: Windows 11
  • Agno Version: v3.0.10 (current main)
  • Additional Environment Details: Python 3.13, anthropic 1.6.0

Possible Solutions (optional)

Parse None, dict, and JSON strings the same way Gemini already does.