You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Gemma4 tool parser raises RecursionError on arguments nested about 1000 levels deep #20995
@NVIDIA/trt-llm-runtime-devs (CODEOWNERS for tensorrt_llm/serve)
Reproduction
fromtensorrt_llm.serve.openai_protocolimportChatCompletionToolsParamfromtensorrt_llm.serve.tool_parser.gemma4_parserimportGemma4ToolParsertools= [ChatCompletionToolsParam(function={"name": "get_weather", "parameters": {"type": "object"}})]
text="<|tool_call>call:get_weather{opts:"+"{a:"*1000+"1"+"}"*1000+"}<tool_call|>"Gemma4ToolParser().detect_and_parse(text, tools)
# RecursionError: maximum recursion depth exceededparser=Gemma4ToolParser()
foriinrange(0, len(text), 4):
parser.parse_streaming_increment(text[i:i+4], tools)
# RecursionError when the call closes
Arrays fail the same way (tags: followed by 1000 [ and 1000 ]).
Expected behavior
The parser returns a result for any model output. Arguments it cannot parse are handled like other malformed arguments, which the parser already logs and skips.
actual behavior
RecursionError leaves detect_and_parse (first parser frame gemma4_parser.py:334) and parse_streaming_increment (first parser frame gemma4_parser.py:476). The non-streaming chat request then fails with HTTP 400 and the generated text is lost. The streaming request ends without its last chunks and without data: [DONE].
additional notes
_parse_gemma4_args calls itself once per nested object (gemma4_parser.py:206), and _parse_gemma4_value and _parse_gemma4_array call each other once per nested array. The handlers at gemma4_parser.py:335 and :478 catch (ValueError, IndexError, TypeError, KeyError). Adding RecursionError there is enough. glm4_parser.py already catches RecursionError for the same reason. I have a fix with a test ready and will open a PR that references this issue.
Activity
[NVIDIA#20995][test] Check each streamed Gemma4 call's final parameters
[NVIDIA#20995][fix] Gemma4 tool parser: handle arguments that nest de…
[NVIDIA#20995][test] Check each streamed Gemma4 call's final parameters