Skip to content

Self-hosted AI workspace.

Python

fix(tools): handle non-dict JSON values in _parse_tool_args (closes #5043) (#5064)

Tanmay Garg53450e2cb152
diff --git a/src/tool_utils.py b/src/tool_utils.py
index bb60a1095..8255bc0a9 100644
--- a/src/tool_utils.py
+++ b/src/tool_utils.py
@@ -54,6 +54,8 @@ def _parse_tool_args(content):
if isinstance(content, str):
try:
args = json.loads(content) if content.strip() else {}
+ if not isinstance(args, dict):
+ args = {}
except (json.JSONDecodeError, TypeError) as e:
raise ValueError(str(e))
elif isinstance(content, dict):
diff --git a/tests/test_admin_tools_registry.py b/tests/test_admin_tools_registry.py
index 4bde9ea9e..0470a0e36 100644
--- a/tests/test_admin_tools_registry.py
+++ b/tests/test_admin_tools_registry.py
@@ -72,3 +72,8 @@ def test_parse_tool_args_lives_in_tool_utils_single_source():
assert _parse_tool_args('{"action":"add"}') == {"action": "add"}
# body-envelope unwrap still works
assert _parse_tool_args('{"body":{"action":"x"}}') == {"action": "x"}
+
+ # non-dict JSON values should return {}
+ assert _parse_tool_args('[1, 2]') == {}
+ assert _parse_tool_args('42') == {}
+ assert _parse_tool_args('"hello"') == {}