Advanced AI-Powered Prompt Generation Custom Node for ComfyUI
Random Prompt Builder for ComfyUI is a professional-grade custom node that brings intelligent AI prompt generation directly into your ComfyUI workflows. This is an adapted version of the standalone Random Prompt Builder desktop application, redesigned to work seamlessly within ComfyUI's node-based interface.
Using local GGUF language models via llama-cpp-python, this node transforms simple descriptions into detailed, structured prompts optimized for various AI image generation models including Stable Diffusion, SDXL, Pony Diffusion, Flux, and more.
- Fully Local Operation: All AI processing happens on your machine using GGUF models
- Model-Aware Formatting: Automatically formats prompts for your target model (tag-based or natural language)
- Advanced Character Control: Detailed customization of physical attributes and characteristics
- Structured Generation: Organizes prompts into semantic categories for consistent results
- GPU Accelerated: Configurable GPU layer offloading for optimal performance
- Style-Aware Output: Multiple style presets with automatic quality tag injection
- Professional Controls: Fine-tune creativity, temperature, and other LLM parameters
- Local LLM integration using GGUF models from your
ComfyUI/models/LLMfolder - GPU acceleration with configurable layer offloading
- Multiple output formats:
- Pony Diffusion (score tags)
- SDXL / SD 1.5 (comma-separated tags)
- Flux / SD3 (natural language)
- Anime/Danbooru (booru tags)
- Custom formats
- Quality tags with automatic style-specific injection
- BREAK separator support for SDXL/Pony workflows
- Seed control for reproducible generation
Define your subject with precision:
- Gender: male, female, non-binary, couple, or any
- Age Range: 18-25, 26-35, 36-50, 50+, or any
- Body Type: slim, average, athletic, curvy, muscular, plus-size, or any
- Ethnicity: caucasian, asian, african, hispanic, middle eastern, mixed, or any
- Height: short, average, tall, or any
- Physical Attributes: breast size, muscle definition (NSFW-aware)
- Scene Type: solo, duo, group, or any
- Character Overlays: furry, monster, sci-fi character traits
- Detailed Attributes: hair style, hair color, eye color, facial hair, roleplay scenarios
Organize your prompt into semantic components:
- Subject: Main character or object description
- Attributes: Physical characteristics, facial features, expressions
- Action: What the subject is doing
- Pose: Body position, stance, gestures
- Clothing: Outfits, accessories, wardrobe details
- Location: Scene setting, environment
- Background: Background elements, atmosphere, lighting
Style Presets:
- Photographic
- Cinematic
- Anime
- Digital Art
- Comic Book
- Fantasy
- Cyberpunk
- 3D Render
- Oil Painting
Style Filters:
- Main Style: Realistic, Anime, Semi-realistic, or any
- Sub-Style (Realistic): Professional, Amateur, Flash, Film, or any
- Sub-Style (Anime): Ghibli, Modern, Vintage, Shoujo, Shounen, or any
Content Controls:
- NSFW Modes: Safe, NSFW, Hardcore
- NSFW Levels: Fine-grained control (0-10)
- Quality tag injection with style-specific enhancers
- Creativity: 0.0 (strict formatting) to 1.0 (highly creative)
- Temperature: 0.1-2.0 (sampling randomness)
- Top-P: Nucleus sampling threshold
- Frequency Penalty: Reduce token repetition
- Presence Penalty: Encourage topic diversity
- Context Window: 512-32768 tokens
- GPU Layers: Offload processing to GPU (0 = CPU only)
- Enhancement Rounds: 0-3 iterations of prompt refinement
- Locked Phrases: Preserve specific text across enhancement iterations
- Selective Enhancement: Toggle person, pose, and location enhancements
- Mandatory Tags: Force-include specific tags in final output
- Negative Prompts: Custom negative prompt support
- Open ComfyUI Manager
- Search for "Random Prompt Builder" or "RandomPromptBuilder"
- Click Install
- Restart ComfyUI
Step 1: Clone the repository
Navigate to your ComfyUI custom nodes directory and clone this repository:
cd ComfyUI/custom_nodes/
git clone https://github.com/yourusername/ComfyUI-RandomPromptBuilder.gitStep 2: Install Python dependencies
cd ComfyUI-RandomPromptBuilder
pip install -r requirements.txtStep 3: Install llama-cpp-python with GPU support
Choose the appropriate installation method for your hardware:
NVIDIA CUDA (Windows):
$env:CMAKE_ARGS="-DGGML_CUDA=on"
pip install llama-cpp-python --upgrade --force-reinstall --no-cache-dirNVIDIA CUDA (Linux/Mac):
CMAKE_ARGS="-DGGML_CUDA=on" pip install llama-cpp-python --upgrade --force-reinstall --no-cache-dirAMD ROCm:
CMAKE_ARGS="-DGGML_HIPBLAS=on" pip install llama-cpp-python --upgrade --force-reinstall --no-cache-dirApple Silicon (Metal):
CMAKE_ARGS="-DGGML_METAL=on" pip install llama-cpp-python --upgrade --force-reinstall --no-cache-dirCPU Only:
pip install llama-cpp-pythonStep 4: Download GGUF model
Download a GGUF model and place it in ComfyUI/models/LLM/ (create the directory if it doesn't exist)
Step 5: Restart ComfyUI
Place GGUF model files in the ComfyUI/models/LLM/ directory.
| Model | Quantization | Size | Download Link | Notes |
|---|---|---|---|---|
| Qwen2.5-7B-Instruct | Q4_K_M | ~4.4GB | HuggingFace | Best balance of quality and speed |
| Qwen2.5-7B-Instruct | Q5_K_M | ~5.4GB | HuggingFace | Higher quality |
| Mistral-7B-Instruct-v0.3 | Q4_K_M | ~4.4GB | HuggingFace | Excellent creativity |
| Llama-3.2-3B-Instruct | Q4_K_M | ~2.0GB | HuggingFace | Lightweight option |
- Q4_K_M: Best speed/quality balance (recommended for most users)
- Q5_K_M: Higher quality with moderate file size increase
- Q6_K: Near-original quality, larger file size
- Q8_0: Maximum quality, largest file size
Step 1: Add the Node
Right-click in ComfyUI → Add Node → Random → Random Prompt Builder (GGUF)
Step 2: Connect Outputs
POSITIVE_PROMPT→CLIPTextEncode(positive)NEGATIVE_PROMPT→CLIPTextEncode(negative)- Connect to your KSampler or other sampling nodes
Step 3: Configure Settings
- Select your GGUF model from the dropdown
- Choose target model format (SDXL, Pony, Flux, etc.)
- Set style preset and NSFW mode
Step 4: Add Prompt Details (Optional)
- Fill in character controls (gender, age, body type, etc.)
- Add structured prompt categories (subject, action, clothing, etc.)
- Add mandatory tags if needed
Step 5: Generate
Click "Queue Prompt" in ComfyUI to generate both positive and negative prompts.
[Random Prompt Builder (GGUF)]
↓ POSITIVE_PROMPT
[CLIP Text Encode (Prompt)]
↓ CONDITIONING
[KSampler] ← + other inputs
↓ LATENT
[VAE Decode]
↓ IMAGE
[Save Image]
Settings:
- Target Model:
Pony (Score Tags) - Style Preset:
Anime - NSFW Mode:
Safe - Use Quality Tags:
True
Character Controls:
- Gender:
female - Age:
18-25 - Body Type:
slim
Structured Inputs:
- Subject:
magical girl - Attributes:
long pink hair, bright eyes, cheerful expression - Clothing:
frilly dress with ribbons - Location:
cherry blossom garden
Generated Output:
score_9, score_8_up, score_7_up, masterpiece, best quality, highres, 18-25 years old, female, slim body type, magical girl, long pink hair, bright eyes, cheerful expression, frilly dress with ribbons, cherry blossom garden
Settings:
- Target Model:
SDXL / SD 1.5 (Tags) - Style Preset:
Photographic - Main Style:
Realistic - Sub Style (Realistic):
Professional - Use BREAK:
True - Use Quality Tags:
True
Character Controls:
- Gender:
female - Age:
26-35 - Body Type:
athletic - Ethnicity:
asian
Structured Inputs:
- Subject:
warrior princess - Attributes:
long flowing black hair, determined expression, battle scars - Action:
looking at camera with confidence - Pose:
dynamic stance, hand on sword hilt - Clothing:
ornate silver armor with red accents, flowing cape - Location:
ancient temple ruins - Background:
mystical fog, moonlight filtering through pillars
Generated Output:
photorealistic, high detail, professional photography, best quality, 8k, BREAK 26-35 years old, asian, female, athletic body type, BREAK warrior princess, long flowing black hair, determined expression, battle scars, BREAK looking at camera with confidence, dynamic stance, hand on sword hilt, BREAK ornate silver armor with red accents, flowing cape, BREAK ancient temple ruins, BREAK mystical fog, moonlight filtering through pillars
Settings:
- Target Model:
Flux / SD3 (Natural) - Style Preset:
Cinematic - Creativity:
0.8
Structured Inputs:
- Subject:
cyberpunk detective - Attributes:
augmented eyes, weathered face - Action:
investigating a holographic crime scene - Location:
neon-lit alley in rain-soaked megacity
Generated Output:
A cinematic scene of a cyberpunk detective with augmented eyes and a weathered face, investigating a holographic crime scene in a neon-lit alley within a rain-soaked megacity. The lighting is dramatic with high contrast, creating a moody atmosphere with shallow depth of field.
| Parameter | Type | Default | Range | Description |
|---|---|---|---|---|
| llm_model | Dropdown | - | - | GGUF model from models/LLM folder |
| gpu_layers | INT | 20 | 0-100 | Number of layers to offload to GPU (0=CPU only) |
| n_ctx | INT | 2048 | 512-32768 | Context window size |
| seed | INT | 0 | 0-∞ | Random seed for reproducibility |
| control_after_generate | Dropdown | randomize | - | "fixed" or "randomize" seed after generation |
| Parameter | Type | Default | Range | Description |
|---|---|---|---|---|
| creativity | FLOAT | 0.8 | 0.0-1.0 | 0.0=strict formatting, 1.0=highly creative |
| temperature | FLOAT | 0.7 | 0.1-2.0 | LLM sampling temperature |
| top_p | FLOAT | 1.0 | 0.0-1.0 | Nucleus sampling threshold |
| frequency_penalty | FLOAT | 0.0 | 0.0-2.0 | Penalize token repetition |
| presence_penalty | FLOAT | 0.0 | 0.0-2.0 | Penalize topic repetition |
| Parameter | Type | Default | Options |
|---|---|---|---|
| target_model | Dropdown | SDXL | Pony, SDXL, Flux, Anime, Custom |
| style_preset | Dropdown | Photographic | Photographic, Cinematic, Anime, Digital Art, Comic Book, Fantasy, Cyberpunk, 3D Render, Oil Painting |
| use_quality_tags | BOOLEAN | True | - |
| use_break | BOOLEAN | False | - |
| Parameter | Type | Default | Options |
|---|---|---|---|
| main_style | Dropdown | any | any, realistic, anime, semi-realistic |
| sub_style_realistic | Dropdown | any | any, professional, amateur, flash, film |
| sub_style_anime | Dropdown | any | any, ghibli, modern, vintage, shoujo, shounen |
| Parameter | Type | Default | Range/Options |
|---|---|---|---|
| nsfw_mode | Dropdown | Safe | safe, nsfw, hardcore |
| nsfw_level | INT | 0 | 0-10 |
| hardcore_level | INT | 0 | 0-10 |
All character parameters support "any" for random selection or "ignore" to exclude from prompt.
| Parameter | Options |
|---|---|
| scene_type | any, solo, duo, group, ignore |
| gender | any, male, female, non-binary, couple, ignore |
| age | any, 18-25, 26-35, 36-50, 50+, ignore |
| body_type | any, slim, average, athletic, curvy, muscular, plus-size, ignore |
| ethnicity | any, caucasian, asian, african, hispanic, middle eastern, mixed, ignore |
| height | any, short, average, tall, ignore |
| breast_size | any, small, medium, large, huge, ignore |
| muscle_definition | any, soft, toned, defined, ripped, ignore |
| hair_style | Free text |
| hair_color | Free text |
| eye_color | Free text |
| facial_hair | any, clean_shaven, stubble, beard, mustache, goatee, ignore |
| character_style | Free text |
| roleplay | Free text |
| Parameter | Type | Default | Description |
|---|---|---|---|
| overlay_furry | BOOLEAN | False | Apply furry character traits |
| overlay_monster | BOOLEAN | False | Apply monster/creature traits |
| overlay_scifi | BOOLEAN | False | Apply sci-fi/cybernetic traits |
| Parameter | Type | Default | Range | Description |
|---|---|---|---|---|
| enhance_round | INT | 0 | 0-3 | Number of enhancement iterations |
| locked_phrases | STRING | "" | - | Phrases preserved across enhancement rounds |
| enhance_person | BOOLEAN | True | - | Enhance character descriptions |
| enhance_pose | BOOLEAN | True | - | Enhance pose descriptions |
| enhance_location | BOOLEAN | True | - | Enhance location descriptions |
All are multiline text inputs:
| Parameter | Description |
|---|---|
| subject | Main subject/character |
| attributes | Physical characteristics, expressions, features |
| action | What they're doing, activity |
| pose | Stance, body position, gestures |
| clothing | Outfit, accessories, wardrobe |
| location | Environment, setting, place |
| background | Background details, atmosphere, lighting |
| Parameter | Type | Default | Range | Description |
|---|---|---|---|---|
| mandatory_tags | STRING | "" | - | Tags forced into output |
| negative_prompt | STRING | "" | - | Custom negative prompt output |
| max_tokens | INT | 512 | 128-2048 | Maximum tokens for LLM generation |
| aspect_ratio | Dropdown | none | - | Target image aspect ratio |
| additional_params | STRING | "" | - | Additional instructions for the LLM |
Adjust gpu_layers based on your GPU VRAM:
| VRAM | Recommended GPU Layers | Model Size |
|---|---|---|
| 24GB+ | 33 (full model) | Any Q4_K_M |
| 12-16GB | 25-30 | Q4_K_M 7B |
| 8-10GB | 15-20 | Q4_K_M 7B |
| 6GB | 10-15 | Q4_K_M 3B |
| 4GB | 0-10 (CPU recommended) | Q4_K_M 3B |
Use enhance_round to iteratively refine prompts:
- 0: No enhancement (direct generation)
- 1: Single refinement pass
- 2: Two refinement passes (high quality)
- 3: Three refinement passes (maximum quality, slower)
When using enhancement rounds, any text in locked_phrases will be preserved exactly across all iterations.
When use_break is enabled, the output is structured with BREAK separators, useful for SDXL and Pony models:
quality tags, BREAK character attributes, BREAK action and pose, BREAK clothing, BREAK location, BREAK background
Use ComfyUI's native batch processing:
- Set
control_after_generateto "randomize" - Use a batch size > 1 in your workflow
- Each batch item receives a unique seed and prompt variation
Solution: Place .gguf model files in the ComfyUI/models/LLM/ folder. Create the directory if it doesn't exist.
Solutions:
- Reduce
gpu_layers(try 15-20 for 8GB VRAM, 10-15 for 6GB) - Use a smaller quantization (Q4_K_M instead of Q5_K_M or Q6_K)
- Use a smaller model size (3B instead of 7B)
- Reduce
n_ctxif you don't need long context
Solutions:
- Increase
gpu_layersif you have VRAM available - Ensure llama-cpp-python was installed with GPU support
- Use a more aggressive quantization (Q4_K_M)
- Reduce
n_ctxto 1024 or 512 - Use a smaller model (3B parameters)
Solution: Install llama-cpp-python:
pip install llama-cpp-pythonFor GPU support, see installation instructions above.
Solutions:
- Increase
temperature(try 0.8-1.0) - Increase
creativity(try 0.7-0.9) - Ensure your model is an instruction-tuned variant (e.g., *-Instruct)
- Try a different model
- Increase
max_tokensto 512 or 1024
Solutions:
- Ensure the folder is named correctly in
custom_nodes/ - Check ComfyUI console for Python errors
- Verify
requirements.txtdependencies are installed - Restart ComfyUI completely
This is normal on the first load. The model is loaded into memory and cached. Subsequent generations will be much faster.
Model loading takes 10-30 seconds on first use. This is normal and only happens once per session.
For Speed:
gpu_layers: 20n_ctx: 1024creativity: 0.7max_tokens: 256
For Quality:
gpu_layers: max availablen_ctx: 2048creativity: 0.8enhance_round: 2max_tokens: 512
- Context Window: Higher
n_ctxallows longer prompts but uses more VRAM. 2048 is usually sufficient. - VRAM Usage: Approximately 4-6GB VRAM for Q4_K_M 7B model with 20-25 GPU layers
- CPU Fallback: If
gpu_layers= 0, generation uses CPU (significantly slower but works on any system)
This ComfyUI node is adapted from the Random Prompt Builder desktop application.
| Feature | Desktop App | ComfyUI Node |
|---|---|---|
| Interface | Electron GUI | ComfyUI Node Parameters |
| Model Loading | node-llama-cpp | llama-cpp-python |
| Batch Processing | Built-in batch UI | Uses ComfyUI batch system |
| History/Favorites | Built-in management | Use ComfyUI workflow saving |
| Prompt Display | Rich text preview | Separate Prompt Display node |
| API Providers | Google Gemini, Custom API | GGUF models only |
| Installation | Standalone executable | ComfyUI custom node |
The core prompt generation logic and LLM system prompts are shared between both versions for consistent output quality.
- Feature parity with main desktop application (98%+)
- Added style filter system (main style + realistic/anime sub-styles)
- Added enhancement iteration system (0-3 rounds + locked phrases)
- Added character overlays (furry, monster, sci-fi)
- Added scene type control (solo, duo, group)
- Extended character attributes (hair, eyes, facial hair, roleplay)
- Added separate enhance toggles (person, pose, location)
- Improved LLM system prompts for better output quality
- Better error handling and user feedback
- Critical fix: Returns single string instead of list (fixes CLIPTextEncode error)
- Added structured prompt categories (attributes, action, background)
- Added character controls (gender, age, body_type, ethnicity, height, physical attributes)
- Added quality tags injection system with 9 style presets
- Added BREAK support for SDXL/Pony workflows
- Added model tuning parameters (top_p, frequency_penalty, presence_penalty)
- Improved LLM system prompts for better structured output
- Changed to control_after_generate for seed management
- Better error handling and model caching
- Initial release with basic GGUF prompt generation
- Support for multiple target model formats
- Basic seed and creativity controls
A companion node for previewing generated prompts in the ComfyUI interface.
Usage:
- Add "Prompt Display (Preview Text)" node
- Connect the
POSITIVE_PROMPTorNEGATIVE_PROMPToutput - The node displays the full prompt text in the node interface
This is helpful for reviewing prompts before they're encoded.
MIT License - See LICENSE file for details.
This project is a ComfyUI adaptation of the Random Prompt Builder desktop application. Both projects are developed by btitkin.
Contributions are welcome. Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-feature) - Commit your changes (
git commit -m 'Add new feature') - Push to the branch (
git push origin feature/new-feature) - Open a Pull Request
When reporting issues, please include:
- ComfyUI version
- Python version
- GPU type and VRAM amount
- GGUF model being used
- Full error message from console
- Node parameter values used
- Original Application: Random Prompt Builder by btitkin
- ComfyUI: ComfyUI by comfyanonymous
- llama.cpp: llama.cpp by Georgi Gerganov
- llama-cpp-python: llama-cpp-python by Andrei Betlen
For questions, issues, or discussions:
- GitHub Issues: Report bugs or request features
- Discussions: Ask questions and share workflows