Skip to content

vllm.parser.granite

Granite parser for JSON-array tool calls.

Granite 3.0/3.1 emit tool calls as a JSON array following a marker::

<|tool_call|> [{"name": "get_weather", "arguments": {"city": "SF"}}]   # 3.0
<tool_call> [{"name": "get_weather", "arguments": {"city": "SF"}}]      # 3.1

<|tool_call|> is a single special token; <tool_call> is plain text. The array may hold several calls, has no closing marker (the ] ends it), and any surrounding prose is content. The engine's tool_call_body_array mode splits the array into one call per element and extracts each name via the name-from-args path; _granite_arg_converter carves the arguments object out of each {"name":..,"arguments":{..}} element. Granite has no reasoning.

_granite_arg_converter(raw_args, partial)

Carve the arguments object out of a {"name":..,"arguments":{..}} array element (see :func:extract_json_member_object).

Source code in vllm/parser/granite.py
def _granite_arg_converter(raw_args: str, partial: bool) -> str:
    """Carve the ``arguments`` object out of a ``{"name":..,"arguments":{..}}``
    array element (see :func:`extract_json_member_object`)."""
    span = extract_json_member_object(raw_args, "arguments")
    if span is None:
        return "" if partial else "{}"
    return span