ComfyUI > Nodes > DJZ-Nodes > Prompt Swap

ComfyUI Node: Prompt Swap

Class Name

PromptSwap

Category
Custom-Nodes
Author
DriftJohnson (Account age: 4052days)
Extension
DJZ-Nodes
Latest Updated
2025-04-25
Github Stars
0.04K

How to Install DJZ-Nodes

Install this extension via the ComfyUI Manager by searching for DJZ-Nodes
  • 1. Click the Manager button in the main menu
  • 2. Select Custom Nodes Manager button
  • 3. Enter DJZ-Nodes 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

Prompt Swap Description

Facilitates dynamic text prompt alteration by swapping specified words/phrases with alternatives for AI model input experimentation.

Prompt Swap:

The PromptSwap node is designed to facilitate the dynamic alteration of text prompts by swapping specified words or phrases with alternatives. This node is particularly useful for AI artists who wish to experiment with different textual inputs to influence the output of AI models, such as those used in generative art or text-based applications. By allowing you to define target words and their corresponding replacements, PromptSwap provides a flexible mechanism to modify prompts without manually editing the text each time. This can be especially beneficial in scenarios where you want to quickly iterate over different variations of a prompt to see how they affect the generated results. The node's primary function is to identify and replace words or phrases in the input text based on a user-defined mapping, ensuring that the replacements are contextually appropriate and maintain the integrity of the original prompt's intent.

Prompt Swap Input Parameters:

text

The text parameter is the main body of text that you wish to modify. It serves as the input prompt where the specified target words will be searched and replaced with their corresponding exchange words. This parameter supports multiline input, allowing for complex and lengthy prompts to be processed. The content of this parameter directly influences the output, as it is the text that undergoes transformation based on the mappings provided in the other parameters.

target_words

The target_words parameter is a string that contains the words or phrases you want to replace in the input text. These words are specified in a comma-separated format and can include phrases enclosed in quotes for more precise matching. The default value is "man, woman, \"no humans\"", which indicates the initial set of words the node will look to replace. This parameter is crucial as it defines the elements in the text that are subject to change, and its configuration directly impacts which parts of the text will be altered.

exchange_words

The exchange_words parameter is a string that lists the replacement words or phrases corresponding to each target word. Like target_words, this parameter uses a comma-separated format and can include quoted phrases. The default value is "woman, man, \"many monsters\"", which provides the initial set of replacements for the target words. The order of words in this parameter should match the order in target_words, as each word or phrase in exchange_words is mapped to the corresponding entry in target_words. This parameter determines the new content that will replace the target words in the text.

Prompt Swap Output Parameters:

STRING

The output parameter is a STRING that represents the modified version of the input text after the specified word swaps have been applied. This output is crucial as it reflects the changes made to the original prompt, showcasing the effect of the word replacements. The modified text can then be used as input for further processing or as a final output, depending on your needs. The output's accuracy and relevance are directly tied to the correct configuration of the input parameters.

Prompt Swap Usage Tips:

  • To ensure accurate replacements, make sure that the target_words and exchange_words are correctly paired and that each target word has a corresponding exchange word.
  • Use quotes around phrases in target_words and exchange_words to handle multi-word replacements effectively, ensuring that the entire phrase is treated as a single unit during the swap.

Prompt Swap Common Errors and Solutions:

Mismatched Target and Exchange Words

  • Explanation: If the number of target words does not match the number of exchange words, the node may not perform as expected.
  • Solution: Ensure that each target word has a corresponding exchange word by checking that both lists have the same number of entries.

Incorrect Quotation Usage

  • Explanation: Misuse of quotes can lead to incorrect parsing of phrases, resulting in unexpected replacements.
  • Solution: Verify that phrases are correctly enclosed in quotes and that there are no unmatched or misplaced quotation marks in the target_words and exchange_words parameters.

Prompt Swap Related Nodes

Go back to the extension to check out more related nodes.
DJZ-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 Playground, enabling artists to harness the latest AI tools to create incredible art.