Skip to content

Bound nesting of model tool-call output in ToolCallParsingUtils.encodeArguments #1111

Closed

Description

@leehack

Follow-up from #1093, section 2. This was there before #1105, which bounds only schema conversion.

As reported in #1093, tool-call model output with about 5,000 nested brackets overflows the Dart stack in ToolCallParsingUtils.encodeArguments. The recursive jsonEncode/jsonDecode path throws StackOverflowError instead of a LlamaException. The output is model-controlled, so a recursive schema such as a $ref tree, or a lazy/auto grammar, can produce it.

Proposed: check nesting depth with the iterative jsonValueDepth helper (lib/src/core/grammar/json_value_depth.dart, added in #1105) before encoding. Alternatively, catch the overflow at the parse boundary and report a LlamaInferenceException (malformed tool call), on both the final and partial parse paths. Add a regression test with nested output on VM and Chrome.

Activity

  1. added
    priority:P3
    on Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority:P3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions