Nodes/comfyUI_LLM/📜 文本数组格式化器
ComfyUI Node

📜 文本数组格式化器

Turn a JSON string array into a real LIST_STR — with a caveat

By XieJunchen·Created about a year ago·Updated about a month ago· 2
📜 文本数组格式化器
    • 长度
    • 字符串数组
    input_str["示例文本1", "示例文本2"]
    show_indextrue
    max_length200
    delimiter|

    LLMs are great at spitting out JSON arrays of text - captions, tag lists, candidate prompts, shot descriptions - and terrible at handing them to ComfyUI in a usable form, because what comes back is just a string. This node, "📜 文本数组格式化器", parses a JSON-format string array and outputs a real LIST_STR plus its length, so the text can flow into nodes that consume actual lists. It's the cleanup step between "LLM said something" and "workflow can iterate over it."

    How it works

    Feed it a string that looks like ["text one", "text two", "text three"] and it runs json.loads, verifies you actually gave it an array, coerces every element to a string (in case the LLM slipped in a number or boolean), and returns the parsed list alongside its length. Malformed input doesn't crash - you get a zero-length list and a Chinese log line ("解析失败", parse failed) in the console. Since it's an output node with IS_CHANGED hashing its input, it re-runs only when the input string actually changes, which matters when the string comes from an LLM call you don't want re-triggering.

    Inputs and outputs

    • input_str (STRING, multiline) - the JSON array text.
    • show_index (BOOLEAN), max_length (INT), delimiter (STRING) - and here's the honest caveat: these exist on the node but the current code largely ignores them. The docstring describes a fancier formatter (index prefixes, truncation, delimiter escaping), but format_array as shipped just validates and returns the raw list plus its length. Don't set expectations that elements come out reformatted - they don't. Maybe a future update finishes the job.
    • Outputs: 长度 ("length", INT) and 字符串数组 ("string array", LIST_STR).

    Wiring it up

    The LIST_STR output is the thing the rest of the pack's text nodes want: feed it straight into StringArrayIndexer to pull individual elements, or into any list-consuming node in the wider ecosystem. The 长度 output is handy for sanity checks and loop bounds - an LLM returning a variable-length array becomes something you can drive logic from.

    Installing it

    ComfyUI Manager → search comfyUI_LLM, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/XieJunchen/comfyUI_LLM
    # restart ComfyUI
    

    Pure Python stdlib, no extra dependencies.

    Where people get burned

    • Strict JSON expected. Trailing commas, single quotes, or an LLM that wrapped the array in prose will fail the parse and silently produce an empty list. Ask your LLM for just the JSON, or clean the string first.
    • Non-array JSON → empty list. A plain string or object input gets rejected, not converted.
    • The formatter params are decorative today. If you came expecting index/truncation formatting, you'll be underwhelmed - this node is currently a validator + converter.

    For "LLM returned an array, now make it usable," it's a small, dependable bridge. Just don't expect it to format anything.

    CategoryLLM/文本处理

    Inputs (4)

    NameTypeDefaultDescription
    input_strSTRING["示例文本1", "示例文本2"]
    show_indexBOOLEANtrue
    max_lengthINT2000–65535
    delimiteroptSTRING|

    Outputs (2)

    NameTypeDescription
    长度INT
    字符串数组LIST_STR