Save 4 hours! We auto-setup your workflow! Free!

Drop your workflow.json — we handle every dependency, custom node, and model. Just open the link and run.

Auto-Setup Workflow Json (Free) Now!
ComfyUI > Nodes > ComfyUI-String-Function

ComfyUI Extension: ComfyUI-String-Function

Repo Name

ComfyUI-String-Function

Author
takkunred (Account age: 0 days)
Nodes
View all nodes(1)
Latest Updated
2026-11-03
Github Stars
0.0K

How to Install ComfyUI-String-Function

Install this extension via the ComfyUI Manager by searching for ComfyUI-String-Function
  • 1. Click the Manager button in the main menu
  • 2. Select Custom Nodes Manager button
  • 3. Enter ComfyUI-String-Function in the search bar
After installation, click the Restart button to restart ComfyUI. Then, manually refresh your browser to clear the cache and access the updated list of nodes.

Visit ComfyUI Online for ready-to-use ComfyUI environment

  • Free trial available
  • 16GB VRAM to 80GB VRAM GPU machines
  • 400+ preloaded models/nodes
  • Freedom to upload custom models/nodes
  • 200+ ready-to-run workflows
  • 100% private workspace with up to 200GB storage
  • Dedicated Support

Run ComfyUI Online

ComfyUI-String-Function Description

ComfyUI-String-Function provides ComfyUI nodes to read and cycle through prompt files, generate or extract LLM image prompts, and search, split, replace, trim, and preview text for image workflows.

ComfyUI-String-Function Introduction

ComfyUI-String-Function is a collection of custom ComfyUI nodes for working with text. It can read prompts from files, move through a list of ideas one at a time, prepare prompts generated by a language model, and make small changes to text before you use it in an image workflow.

This is useful when you want to:

  • Keep prompts in text files instead of pasting them into ComfyUI repeatedly.
  • Generate images from a different line or file on each workflow run.
  • Turn a language model’s conversational response into a usable image prompt.
  • Separate a positive prompt from a negative prompt.
  • Clean up, split, search, or replace parts of a prompt without editing it by hand.

The extension processes text; it does not generate images or include an image-generation model. You can connect its text outputs to other nodes in your ComfyUI workflow.

How ComfyUI-String-Function Works

Think of each node as a small text tool. One node can read a file, another can pick out the part you need, and another can show you the result. You connect them in the order that suits your workflow.

For example, you could save one prompt per line in a text file and use File Read Line to supply a line on each run. When it reaches the final line, it starts again at the beginning. Or you could ask a language model to write a prompt, then use String Extract Prompt to remove introductory wording and keep the prompt itself.

Several nodes also provide information about their result. File Read reports whether reading succeeded; String Extract Prompt reports which extraction method it used; and String Find reports a character position. These extra outputs can help you check what happened when a workflow produces an unexpected result.

Choosing a language-model prompt workflow

You have two approaches described in this README:

  • LM Studio Prompt Generator sends your theme to LM Studio and returns a positive prompt, a negative prompt, and the original response from one node. Its structured-output setting is designed to keep the response in a predictable format.
  • String Extract Prompt works with text produced elsewhere, including a separate language-model node. It is useful when you already have an LLM workflow or need to handle varied response formats.

You can use Prompt Preview with either approach to inspect the text before it reaches later nodes.

ComfyUI-String-Function Features

Read prompts from files

NodeWhat it doesWhen to use it
File ReadReads the entire contents of one text file.You keep a complete prompt or set of instructions in a file.
File Read LineReturns one line per run, then loops back to the first line.You have one prompt or idea per line.
Folder File ReadReturns the contents of one file per run, then loops through the folder again.You keep separate prompt files for different concepts.

File Read takes a file_path and returns text, line_count, and success. If the file does not exist, success is False. Its strip_newline_end setting, on by default, removes a newline at the very end of the file. The node also removes surrounding double quotes from a pasted path, and its Browse file button opens a file-selection dialog.

All three file-reading nodes offer an encoding setting. The default, auto, tries utf-8-sig, then utf-8, then cp932. If a file does not read correctly, you can choose one explicitly: utf-8, utf-8-sig for files with a UTF-8 byte-order mark, or cp932 for some Japanese Windows text files.

File Read Line returns line_text, a one-based line_index, line_count, and is_last. Choose sequential to follow the file’s order or shuffle to use each line once in a shuffled order before reshuffling. Set skip_empty_lines to True when blank lines should not count as entries. Set reset to True on a run when you want to restart from the beginning. Each node keeps its own position in memory, so restarting ComfyUI resets it.

Folder File Read offers the same sequential, shuffle, and reset controls for files. Its extension_filter defaults to .txt; enter a comma-separated list such as .txt,.md to include more types, or leave it blank to include all files. In sequential mode, sort_order can follow filenames from A to Z or Z to A, or modification times from oldest to newest or newest to oldest. The outputs include the file’s text, name, full path, one-based position, total number of matching files, and is_last. A Browse folder button opens a folder-selection dialog. Its position also resets when ComfyUI restarts.

Generate and extract image prompts

LM Studio Prompt Generator combines the theme you provide, an LM Studio text-generation request, and extraction of prompt and negative_prompt into one node. It also returns raw_text, method_used, and success.

Key settings include:

SettingWhat it changes
themeThe image idea you send to the language model.
system_promptInstructions for writing the image prompt. You do not need to specify the output format; the node supplies that instruction.
model_keyThe LM Studio model key. Leave it empty to use a loaded model detected by the node.
structured_outputOn by default. Requests JSON Schema output; when off, the node requests a PROMPT: / NEGATIVE: format instead.
generate_negativeOn by default. Controls whether a negative prompt is generated.
seed-1 uses a random seed on each run.
max_tokens and temperatureControl the response length limit and generation behavior; the defaults are 4096 and 0.7.
strip_thinkingOn by default. Removes thinking content from raw_text.
timeout_secondsHow long to wait for a response; the default is 300.
debugPrints request and response information to the console when enabled.

The node also has auto_unload and unload_delay controls for unloading a model after generation. A delay above zero is a time-to-live in seconds; immediate unloading at a delay of zero requires the lmstudio SDK. If LM Studio cannot be reached or times out, the node stops the workflow with an error rather than passing along an empty prompt.

String Extract Prompt takes LLM output and returns prompt, method_used, and success. Its default auto mode tries several recognizable formats in order: a value in JSON, text in a suitable code block, text after a label such as Prompt:, and finally approaches that remove introductory wording or identify a comma-heavy prompt paragraph.

You can choose a specific extraction mode when you know the response format:

ModeWhat it looks for
jsonA value under one of the names in json_key, including in nested or partially cut-off JSON.
code_blockPrompt text inside a code block; language-labelled blocks such as JSON or YAML are excluded.
after_labelText following a label listed in label_names.
strip_preamblePrompt text after removing introductory or closing wording, quotation marks, and a separate negative-prompt paragraph.
most_commasThe paragraph with the most commas, useful for tag-style prompts.
first_lineThe first nonempty line after introductory wording is removed.
rawThe cleaned input without further extraction.

The default json_key list is prompt,positive_prompt,positive,description,text,content, in priority order. Key matching ignores capitalization and differences involving spaces, underscores, and hyphens. strip_think_blocks is on by default to remove supported thinking sections before extraction. If auto cannot confidently identify a prompt, fallback_to_raw=True returns cleaned text with success=False; setting it to False returns an empty result instead.

To extract both fields from an LLM response, use two String Extract Prompt nodes: one with json_key=prompt, and another with mode=json, json_key=negative_prompt, and fallback_to_raw=False. The second node then returns an empty string if the response has no negative prompt, rather than treating the whole response as one. See the example workflow:

Example String Extract Prompt workflow

If you configure Structured Output directly in LM Studio for this two-node workflow, the author provides this schema:

{
  "type": "object",
  "properties": {
    "prompt": {
      "type": "string",
      "description": "Main prompt (comma-separated tags)"
    },
    "negative_prompt": {
      "type": "string",
      "description": "Negative prompt"
    }
  },
  "required": ["prompt", "negative_prompt"],
  "additionalProperties": false
}

Prompt Preview displays prompt, negative_prompt, and raw_text together on the node. All three inputs are optional, and the node passes each supplied value through unchanged. Place it between extraction and your later text-encoding nodes when you want to inspect what the model actually returned.

Edit and inspect text

These smaller nodes let you adjust prompts without changing the original file or LLM response:

NodePurpose and example
String FindFinds the position of text. Positions start at 1; 0 means no match. Use start_pos and occurrence to search later in the text or find a later occurrence.
String SplitSplits text into before and after at a delimiter. Choose which occurrence to split at, or set use_last=True to split at the final one.
String Left / Mid / RightTakes a specified number of characters from the beginning, from a chosen starting position, or from the end of text.
String DefaultSupplies default_value when text is empty. Set trim_before_check=True if text containing only surrounding whitespace should be treated as empty. It also returns was_empty.
String ReplaceReplaces old text with new text. count=-1 replaces every occurrence; a smaller count limits replacements. Set case_sensitive=False to ignore capitalization. It reports replace_count.
String TrimRemoves whitespace, or characters you specify in chars, from both ends (both), only the beginning (left), or only the end (right). It does not remove matching content from the middle.
String CaseChanges capitalization using upper, lower, title, capitalize, or swapcase. For example, title turns hello world into Hello World.
String Regex MatchFinds text using a pattern. Use it when an ordinary search is not flexible enough, such as extracting numbers with \d+.

String Regex Match has four search modes: search finds a match anywhere, match checks from the start, fullmatch requires the whole text to match, and findall collects all matches. group=0 returns the entire match; another group number returns a parenthesized part of the pattern. You can also ignore case, make ^ and $ apply to individual lines with multiline, and choose the separator used to join findall results with join_str. Its outputs are result, matched, and match_count.

For example, the pattern (\d{4})-(\d{2})-(\d{2}) with mode=search and group=2 extracts the month from a date written as YYYY-MM-DD.

ComfyUI-String-Function Models

ComfyUI-String-Function does not provide its own image or language models. LM Studio Prompt Generator uses a model available through LM Studio; you can specify its model_key or leave the field empty to use a detected loaded model.

String Extract Prompt is designed to handle text from several model families and response styles. These are compatibility examples, not models bundled with the extension:

Model or response styleWhat the extraction node handles
Qwen3 and DeepSeek-R1Supported <think> sections, including certain incomplete tags.
gpt-ossIts channel-formatted response, keeping the final response rather than analysis content.
Llama 3, Qwen ChatML, Gemma, and MistralSupported assistant-role markers and other conversation-format tokens.
Conversational responses generallyIntroductory wording, Markdown prompt labels, closing remarks, and accompanying negative prompts.

A descriptive sentence such as “The image shows a cat...” may itself be the intended prompt. The extraction node does not remove it merely because it reads like prose.

Troubleshooting ComfyUI-String-Function

A file cannot be read

  1. Check that file_path points to an existing file, or use the node’s Browse file button to select it.
  2. Inspect File Read’s success output. False indicates that reading did not succeed, including when the file does not exist.
  3. If the path was pasted with double quotes around it, you can leave them in place; File Read removes surrounding double quotes automatically.
  4. If the file’s text does not read correctly, try an explicit encoding instead of auto.

A line or folder workflow keeps returning an unexpected item

  1. Check whether mode is sequential or shuffle. Shuffle uses every item before reshuffling, but does not follow file order.
  2. For File Read Line, check skip_empty_lines if blank lines appear or the count differs from what you expected.
  3. For Folder File Read, check extension_filter and, in sequential mode, sort_order.
  4. Set reset=True for a run to start over. Remember that restarting ComfyUI also resets the positions kept in memory.

Prompt extraction returns too much text or the wrong field

  1. Inspect the complete LLM response with Prompt Preview.
  2. If the response is JSON, use mode=json and set json_key to the exact field you want, such as prompt or negative_prompt.
  3. If the response uses a visible label, try mode=after_label and add that label to label_names.
  4. Check method_used and success. A raw fallback with success=False means the node could not confidently identify the prompt.
  5. For a negative-prompt extraction node, set fallback_to_raw=False so a missing field does not become an unintended negative prompt.

LM Studio Prompt Generator stops the workflow

A connection failure or timeout is reported as an error. Check that LM Studio is available at the address configured for the node; the default address is http://localhost:1234. For an LM Studio server on another computer, its server settings must allow local-network access, and the relevant firewall port must be open. The author notes that the .env settings are read on each execution, so changing the configured address does not require restarting ComfyUI.

Frequently asked questions

Do I need an LLM to use this extension?
No. The file-reading and general string nodes work with text independently of the LM Studio prompt workflow.

Will File Read Line eventually repeat a prompt?
Yes. Sequential mode returns to the first line after the last. Shuffle mode reshuffles after all eligible lines have been used.

Can I keep positive and negative prompts separate?
Yes. LM Studio Prompt Generator supplies separate outputs. With another LLM node, use separate String Extract Prompt nodes configured for the two fields.

Does Prompt Preview change my prompt?
No. It displays the supplied values and passes them through unchanged.

Learn More about ComfyUI-String-Function

  • Explore the author’s repository for the extension’s source and accompanying files.
  • Study the example prompt-extraction workflow alongside its workflow image to see how an LLM response, positive prompt, negative prompt, and preview node can be connected.

The extension is provided under the MIT License.

ComfyUI-String-Function Related Nodes

RunComfy
Copyright 2025 RunComfy. All Rights Reserved.

RunComfy is the premier ComfyUI platform, offering ComfyUI online environment and services, along with ComfyUI workflows featuring stunning visuals. RunComfy also provides AI Models, enabling artists to harness the latest AI tools to create incredible art.

ComfyUI-String-Function detailed guide | ComfyUI