Nodes/Comfy Text Stats/Text -> Line Batch Chunk
ComfyUI Node

Text -> Line Batch Chunk

Page through your prompts and captions in fixed-size batches

By scofano·Created 11 months ago·Updated 3 months ago· 3
Text -> Line Batch Chunk
    • chunk_text
    text
    number_of_lines2
    batch1

    When you've got a long multiline list - a hundred captions, a prompt sheet, a subtitle block - and you want to hand it to something downstream a few lines at a time, this node is the pager. number_of_lines sets the page size, batch picks the page, and chunk_text gives you just those lines. It's one of the eight text utilities in the Comfy Text Stats pack from scofano, and like the rest of it, pure Python with nothing to install beyond the pack itself.

    How it works

    It splits the text on newlines and slices from (batch - 1) * number_of_lines forward by number_of_lines. Nothing clever, which is the point. Two edge behaviors are worth knowing: if the last chunk is short, you get the partial chunk, and if the requested batch starts past the end of the text, you get an empty string rather than an error.

    The one thing that genuinely surprises people is the batch widget. It's flagged with control_after_generate = "increment" - the same seed-style auto-increment ComfyUI applies to seed fields - so every time you run the graph, batch ticks up by one and you page forward automatically. That's usually exactly what you want when stepping through a dataset, and exactly not what you want when you're debugging and it silently moves on underneath you. You can type a new value any time to jump or reset.

    Inputs and output

    Three inputs, two of which matter:

    • text - the multiline string to slice.
    • number_of_lines - lines per chunk, minimum 1, default 2.
    • batch - which chunk to return, starting at 1. This is the one that auto-increments.

    Output: chunk_text, a STRING containing just those lines. Feed it into an LLM node, a caption combiner, or anything else that takes text.

    Installing it

    The node comes in the Comfy Text Stats pack. ComfyUI Manager route: Manager → Custom Nodes Manager → search "Comfy Text Stats" → Install, then restart ComfyUI. Or manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/scofano/comfy-text-stats
    

    Then restart. No extra dependencies, no model downloads - the pack's requirements file is just a comment saying so.

    Where people get burned

    • Watch the auto-increment. Run the graph twice with "identical" inputs and wonder why the output changed? That's batch bumping itself, not a bug.
    • It's line-based via splitlines(), so blank lines count as lines and shift your chunks. Run this pack's Remove Empty Lines first if your source has stray blanks.
    • Out-of-range requests return an empty string, not an error, so a downstream node that assumes non-empty text can silently stall. If your LLM gets nothing and you don't know why, check whether the batch number is past the end of your list.
    CategoryText/Utils

    Inputs (3)

    NameTypeDefaultDescription
    textSTRING
    number_of_linesINT2
    batchINT1

    Outputs (1)

    NameTypeDescription
    chunk_textSTRING