{"record":{"id":"f7956ac271e74f76","repo":"sgl-project/sglang","slug":"tool-call-format-error","errorCode":null,"errorMessage":"Tool call format error","messagePattern":"Tool call format error","errorType":"exception","errorClass":"DS32EncodingError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/entrypoints/openai/encoding_dsv32.py","lineNumber":370,"sourceCode":"    if matched_stop:\n        content = text[index:min_pos]\n        return min_pos + len(matched_stop), content, matched_stop\n    else:\n        content = text[index:]\n        return len(text), content, None\n\n\ndef parse_tool_calls(index: int, text: str):\n    tool_calls: List[Dict[str, Any]] = []\n    stop_token = None\n    tool_calls_end_token = f\"</{dsml_token}function_calls>\"\n\n    while index < len(text):\n        index, _, stop_token = _read_until_stop(\n            index, text, [f\"<{dsml_token}invoke\", tool_calls_end_token]\n        )\n        if _ != \">\\n\":\n            raise DS32EncodingError(\"Tool call format error\")\n\n        if stop_token == tool_calls_end_token:\n            break\n\n        if stop_token is None:\n            raise DS32EncodingError(\"Missing special token\")\n\n        index, tool_name_content, stop_token = _read_until_stop(\n            index, text, [f\"<{dsml_token}parameter\", f\"</{dsml_token}invoke\"]\n        )\n\n        p_tool_name = re.findall(\n            r'^\\s*name=\"(.*?)\">\\n$', tool_name_content, flags=re.DOTALL\n        )\n        if len(p_tool_name) != 1:\n            raise DS32EncodingError(\"Tool name format error\")\n        tool_name = p_tool_name[0]\n","sourceCodeStart":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/entrypoints/openai/encoding_dsv32.py#L352-L388","documentation":"While parsing model output, the text after a '<<dsml>>invoke' token must start with '>\\n'. parse_tool_calls raises DS32EncodingError('Tool call format error') when the invocation opening is malformed.","triggerScenarios":"Completion text contains a malformed tool invocation, e.g. '<|tool_calls_begin|>invokefunc<|dsml|>...' where the char(s) after 'invoke' are not '>\\n' — typically from model hallucination or truncated generation.","commonSituations":"Model outputs broken DSML when tool schemas confuse it; max_tokens cuts mid-invocation; prompt/template drift between model version and parser tokens.","solutions":["Check that the chat template/tool tokens match the deployed model version.","Increase max_tokens so invocations are not truncated.","Retry or treat the completion as plain text if no valid tool call is present."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from sglang.srt.entrypoints.openai.encoding_dsv32 import DS32EncodingError\ntry:\n    calls=parse_tool_calls(text)\nexcept DS32EncodingError:\n    calls=None  # treat completion as plain text","preventionTips":["Match parser tokens to model version.","Set generous max_tokens for tool-call turns."],"tags":["deepseek","tool-parsing","model-output"],"backgroundTag":"model-output-parse-failure","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}