Load Text Line From File (Buff)
Turn a prompt library .txt into a seeded, weighted line on demand
- text
- source_file
- line_count
This is the node you reach for when your prompts live in a text file and you want a workflow to pull one out - randomly, by index, or in order - and feed it straight into a CLIP encoder. LoadTextLineFromFile reads a .txt or .csv, filters out noise, applies transformations, and hands back a clean string plus the source file and line count as separate outputs.
If you've ever maintained a "prompt library" of a hundred ideas in a notebook, this is how you turn it into something a workflow can consume. Random mode with a seed gives you reproducible surprise: same seed, same file, same line, every time. Sequential mode walks the file one line per run and wraps around, which pairs beautifully with batch queueing. And the all mode joins every line into one blob - useful for dumping a whole tag set into a prompt.
How it works
Read the file, split into lines, filter. The filtering is the quiet workhorse: skip_comments drops lines starting with #, skip_blank_lines clears whitespace-only lines, strip_whitespace trims. Then the line is selected by your selection_mode - random via a seeded random.Random, index with wrap-around, sequential via a per-file counter, or all-lines-joined. After selection it can replace_underscores with spaces, remove ban_tags (comma-separated words stripped out of the output, with leftover commas cleaned up), prepend prefix, append suffix, and - the trick that makes it ComfyUI-native - if weight is non-zero it wraps the whole thing as (text:weight) so prompt weighting syntax just works in your CLIP encoder.
There's a text_override input too: feed it a string (convert to a wire input via right-click) and it skips file reading entirely while still applying all the selection and filtering. Good for testing without touching disk.
Inputs that matter
file_path- a text file, or a directory (withpick_random_file_from_diron, a random.txtis chosen from it, recursive). Quotes are stripped automatically.selection_mode-random,index,all, orsequential.seed/index- for the matching modes.encoding- utf-8, utf-8-sig, latin-1, ascii, cp1252. If you see mojibake or BOM garbage, this is the fix.weight,prefix,suffix,ban_tags- the formatting layer.
Outputs: text (the line), source_file (path or <text_override>), and line_count (after filtering - useful for validation).
Install
From BuffMcBigHuge's pack - ComfyUI Manager (search "ComfyUI-Buff-Nodes") or:
cd ComfyUI/custom_nodes
git clone https://github.com/BuffMcBigHuge/ComfyUI-Buff-Nodes
Restart ComfyUI. No dependencies beyond stock ComfyUI.
Gotchas
The usual: bad path returns empty text with a console note, so wire defensively. Sequential mode uses IS_CHANGED to force a re-run every execution - that's deliberate, and it means this node re-executes even when nothing upstream changed, which can defeat caching for things behind it (the classic trade-off, explained in comfyui-node-plumbing.md). Line counting happens after filtering, so a file of 50 lines with 10 comments reports 40. If you're picking lines from a .csv, the whole row comes back as one string - great for prompt columns, but don't expect parsing. Small scope, but it's the cleanest way I know to make a prompt library actually drive generations.
Inputs (16)
| Name | Type | Default | Description |
|---|---|---|---|
| file_path | STRING | Path to a text file (.txt, .csv, etc.) or a directory. When a directory is given, a random .txt file is selected from it. Surrounding quotes are stripped automatically. | |
| selection_mode | COMBO | random | random: Pick a random line (seeded). index: Pick a specific line by index number. all: Return every line joined by the join_delimiter. sequential: Cycle through lines in order across executions. |
| seed | INT | 00–18446744073709550000 | Seed for random selection. Same seed + same file = same line. |
| index | INT | 00–18446744073709550000 | Line index to retrieve when selection_mode is 'index'. Wraps around if out of range. |
| text_overrideopt | STRING | When provided, this text is used instead of reading from file_path. All line selection and filtering still applies. Right-click and Convert to Input to connect a wire instead. | |
| encodingopt | COMBO | utf-8 | File encoding to use when reading the text file. |
| ban_tagsopt | STRING | Comma-separated list of tags/words to remove from the output. Surrounding commas and extra spaces are cleaned up. | |
| prefixopt | STRING | Text to prepend to the output. | |
| suffixopt | STRING | Text to append to the output. | |
| join_delimiteropt | STRING | , | Delimiter used to join lines when selection_mode is 'all'. |
| weightopt | FLOAT | 0.00-10–10 | When non-zero, wraps output as (text:weight) for prompt weighting. |
| skip_commentsopt | BOOLEAN | true | Skip lines starting with '#' (after stripping whitespace). |
| skip_blank_linesopt | BOOLEAN | true | Skip empty or whitespace-only lines. |
| strip_whitespaceopt | BOOLEAN | true | Strip leading/trailing whitespace from each line. |
| replace_underscoresopt | BOOLEAN | false | Replace underscores with spaces in the output text. |
| pick_random_file_from_diropt | BOOLEAN | false | When True and file_path is a directory, pick a random .txt file from it. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| text | STRING | — |
| source_file | STRING | — |
| line_count | INT | — |