PromptJSON: custom node for ComfyUI that reformats prompts in various Schema using an LLM
Details
Download Files
Model description
PromptJSON Node for ComfyUI
Description
PromptJSON is a custom node for ComfyUI that structures natural language prompts and generates prompts for external LLM nodes in image generation workflows. It aids in creating consistent, schema-based image descriptions with support for various schema types.
Features
Structures natural language prompts according to multiple schema types
Generates prompts for external LLM nodes with multiple strategies
Supports negative prompts
Adjustable complexity for output detail
Custom schema support for fine-tuning prompt structure
Multiple prompt generation strategies (One Shot and Few Shot)
Support for various schema types: JSON, HTML, Key-Value, Attribute-Based, Visual Layer Breakdown, Compositional Grid, and Artistic Reference
Error handling for robust operation
Installation
Navigate to your ComfyUI custom nodes directory.
Clone this repository or copy the
PromptJSON.py,prompt_templates.py, and__init__.pyfiles into a new directory namedComfyUI-PromptJSON.Restart ComfyUI or refresh your workflow.
Usage
Find the "Prompt JSON" node in the "prompt_converters" category in ComfyUI.
Connect the following inputs:
prompt: Your main prompt textnegative_prompt: Elements to avoid in the imagecomplexity: A float value between 0.1 and 1.0 to adjust output detailllm_prompt_type: Choose between "One Shot" or "Few Shot"schema_type: Select from JSON, HTML, Key, Attribute-Based, Visual Layer Breakdown, Compositional Grid, or Artistic Referencecustom_schema(optional): Custom schema string (format depends on chosen schema type)
Use the outputs:
system_prompt: The system instructions for the LLMuser_prompt: The main prompt for the LLM, including the structured inputnegative_passthru: The negative prompt passed through unchangedschema: The formatted schema used for structuring the prompt
LLM Prompt Types
One Shot: Provides a single example of a structured response based on the input prompt.
Few Shot: Provides multiple examples of structured responses at different complexity levels.
Schema Types
JSON: Traditional JSON structure for detailed image descriptions.
HTML: HTML-like tag structure for organizing image elements.
Key: Key-value pair structure for straightforward descriptions.
Attribute-Based: List of attributes focusing on specific aspects of the image.
Visual Layer Breakdown: Structured description of background, midground, foreground, and focus elements.
Compositional Grid: 3x3 grid-based description of image elements.
Artistic Reference: Detailed breakdown of artistic elements like subject, composition, color palette, etc.
Workflow
The PromptJSON node takes the user's input and structures it according to the chosen schema type.
It generates a system prompt and user prompt based on the chosen LLM prompt type and schema.
The outputs can be sent to an external LLM node for further processing.
The external LLM node generates the final, detailed image description based on these prompts.
Custom Schema
The custom schema feature allows you to define the structure of the output. The format depends on the chosen schema type. For example, for JSON:
{
"scene": {
"time_of_day": "string",
"weather": "string",
"location": "string"
},
"subjects": [
{
"type": "string",
"description": "string",
"position": "string"
}
],
"style": {
"artistic_movement": "string",
"color_palette": ["string"],
"mood": "string"
},
"camera": {
"angle": "string",
"shot_type": "string"
}
}
Example Output
Input:
prompt: "A serene lake at sunset with a lone fisherman in a small boat"
negative_prompt: "urban, city, crowds"
complexity: 0.7
llm_prompt_type: "Few Shot"
schema_type: "JSON"
custom_schema: (The JSON schema shown above)
Output:
System Prompt: (Contains instructions and examples for the LLM)
User Prompt: (Contains the structured input prompt and schema)
Negative Passthru: "urban, city, crowds"
Schema: (The formatted JSON schema)
Notes
The system prompt and user prompt are designed to guide an external LLM in generating a detailed, structured image description.
Experiment with different LLM prompt types and schema types to find the most effective combination for your specific use case.
Adjust the complexity parameter to control the level of detail in the generated prompts.
Custom schemas allow for fine-tuned control over the structure of the generated descriptions.
Support
For issues, feature requests, or contributions, please open an issue or pull request in the GitHub repository.








