sgl-project/sglang · error · ValueError
Assistant tool call function.arguments must be a JSON object
Error message
Assistant tool call function.arguments must be a JSON object.
What it means
encode_arguments_to_dsml requires tool_call['arguments'] to decode to a JSON object (dict). If the string parses to a list/number, or the value itself is not a dict, ValueError is raised.
Source
Thrown at python/sglang/srt/entrypoints/openai/encoding_dsv4.py:175
def encode_arguments_to_dsml(tool_call: Dict[str, str]) -> str:
"""
Encode tool call arguments into DSML parameter format.
Args:
tool_call: Dict with "name" and "arguments" keys.
Returns:
DSML-formatted parameter string.
"""
p_dsml_template = '<{dsml_token}parameter name="{key}" string="{is_str}">{value}</{dsml_token}parameter>'
P_dsml_strs = []
raw_arguments = tool_call["arguments"]
arguments = (
json.loads(raw_arguments) if isinstance(raw_arguments, str) else raw_arguments
)
if not isinstance(arguments, dict):
raise ValueError(
"Assistant tool call function.arguments must be a JSON object."
)
for k, v in arguments.items():
p_dsml_str = p_dsml_template.format(
dsml_token=dsml_token,
key=k,
is_str="true" if isinstance(v, str) else "false",
value=v if isinstance(v, str) else to_json(v),
)
P_dsml_strs.append(p_dsml_str)
return "\n".join(P_dsml_strs)
def decode_dsml_to_arguments(
tool_name: str, tool_args: Dict[str, Tuple[str, str]]
) -> Dict[str, str]:View on GitHub (pinned to 0132848349)
Solutions
- Make arguments a JSON object string, e.g. '{"query": "..."}'.
- If arguments are legitimately an array, wrap them: '{"items": [...]}'.
- Validate tool_call arguments with json.loads + isinstance dict before sending history back.
Example fix
# before
{"name":"search","arguments":"[\"a\",\"b\"]"}
# after
{"name":"search","arguments":"{\"terms\":[\"a\",\"b\"]}"} Defensive patterns
Strategy: type-guard
Validate before calling
import json args=json.loads(tc['function']['arguments']) if isinstance(tc['function']['arguments'],str) else tc['function']['arguments'] assert isinstance(args,dict)
Type guard
def args_is_dict(tc):
a=tc['function']['arguments']
a=json.loads(a) if isinstance(a,str) else a
return isinstance(a,dict) Prevention
- Always serialize tool arguments as JSON objects.
- Wrap non-object payloads in a named key.
When it happens
Trigger: Assistant tool_call with function.arguments = '[1,2]' (JSON array string), '"42"', or a raw non-dict value like a list passed directly.
Common situations: Agents recording tool calls whose arguments were arrays; clients storing pre-serialized non-object JSON; upstream model emitting malformed arguments.
Related errors
- Invalid messages at {index}: {assistant_msg}
- No tool calls but found tool output
- sparse_attn_v4_paged_decode expects fp16/bf16 q, got {q.dtyp
- bad compress_ratio {compress_ratio}
- Unsupported d_qk: {d_qk}. Expected {DSV4_D_QK} (DeepSeek V4)
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/4ab7164778b90723.
Report an issue: GitHub.