fix: crash on None entry in tool_calls list during Anthropic conversion (#2209)

If a tool_calls list contains a None entry (from malformed API response,
compression artifact, or corrupt session replay), convert_messages_to_anthropic
crashes with AttributeError: 'NoneType' object has no attribute 'get'.

Skip None and non-dict entries in the tool_calls iteration. Found via
chaos/fuzz testing with mixed valid/invalid tool_call entries.
This commit is contained in:
0xbyt4 2026-03-20 22:01:42 +03:00 committed by GitHub
parent aafe86d81a
commit 0ce35a117c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -864,6 +864,8 @@ def convert_messages_to_anthropic(
else:
blocks.append({"type": "text", "text": str(content)})
for tc in m.get("tool_calls", []):
if not tc or not isinstance(tc, dict):
continue
fn = tc.get("function", {})
args = fn.get("arguments", "{}")
try: