fix: tolerate RecursionError when decoding tool-call arguments

json.loads raises RecursionError (not JSONDecodeError) on deeply nested
input, which propagated and dropped the affected span. Fall back to the
raw string like any other undecodable payload.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Ambuj Upadhyay 2026-08-15 00:13:55 +05:30
parent 08a7a62321
commit 197d7e4fa9
2 changed files with 12 additions and 1 deletions

View file

@ -57,7 +57,7 @@ def _parse_tool_call_arguments(raw: object) -> object:
return raw
try:
return json.loads(raw)
except json.JSONDecodeError:
except (RecursionError, json.JSONDecodeError):
return raw

View file

@ -366,3 +366,14 @@ class TestDataDogLLMObsCacheTokenMetrics:
assert "cache_write_input_tokens" not in metrics
assert "non_cached_input_tokens" not in metrics
assert metrics["input_tokens"] == 20.0
def test_parse_tool_call_arguments_survives_deeply_nested_json():
"""A hostile/degenerate arguments string must fall back to the raw
string, not raise RecursionError and drop the span."""
from litellm.integrations.datadog.datadog_llm_obs import (
_parse_tool_call_arguments,
)
hostile = "[" * 50000
assert _parse_tool_call_arguments(hostile) == hostile