Resolves #8899 This implementation adds a comprehensive JSON Schema for the ComfyUI Prompt API format to improve developer experience and API integration. Features: - JSON Schema definition for prompt format validation - Optional schema validation via ?validate_schema=true parameter - New /schema/prompt endpoint to serve the schema - Comprehensive documentation and examples - Backward compatible - no breaking changes Implementation: - api_schemas/prompt_format.json: Complete JSON Schema definition - api_schemas/validation.py: Validation utilities with graceful fallback - api_schemas/README.md: Detailed documentation and usage examples - server.py: Added schema endpoint and optional validation The schema validates: - Prompt structure and required fields - Node definitions with class_type and inputs - Connection format [node_id, output_slot] - Optional metadata like prompt_id, client_id, etc. Schema validation is opt-in via query parameter to ensure no breaking changes. If jsonschema package is not installed, validation is skipped with a warning. |
||
|---|---|---|
| .. | ||
| __init__.py | ||
| prompt_format.json | ||
| README.md | ||
| validation.py | ||
ComfyUI Prompt API JSON Schema
This directory contains JSON Schema definitions for the ComfyUI API, providing formal specification, validation, and IDE support for API integrations.
📁 Files
prompt_format.json- JSON Schema for the/promptendpoint request formatvalidation.py- Python utilities for schema validationREADME.md- This documentation file
🚀 Quick Start
1. Get the Schema
The JSON Schema is available at: GET /schema/prompt or GET /api/schema/prompt
curl http://localhost:8188/schema/prompt
2. Enable Validation (Optional)
Add ?validate_schema=true to your POST requests for server-side validation:
curl -X POST http://localhost:8188/prompt?validate_schema=true \
-H "Content-Type: application/json" \
-d @your_prompt.json
3. IDE Setup
Most modern IDEs support JSON Schema for autocomplete and validation:
VS Code:
{
"json.schemas": [
{
"fileMatch": ["**/comfyui_prompt*.json"],
"url": "http://localhost:8188/schema/prompt"
}
]
}
IntelliJ/PyCharm: Settings → Languages & Frameworks → Schemas and DTDs → JSON Schema Mappings
📋 Schema Overview
The prompt format schema defines the structure for ComfyUI workflow execution requests:
{
"prompt": {
"1": {
"class_type": "CheckpointLoaderSimple",
"inputs": {
"ckpt_name": "model.safetensors"
}
},
"2": {
"class_type": "CLIPTextEncode",
"inputs": {
"text": "a beautiful landscape",
"clip": ["1", 1]
}
}
},
"prompt_id": "optional-uuid",
"client_id": "optional-client-id"
}
Key Properties
prompt(required) - The node graph defining the workflowprompt_id(optional) - Unique identifier for tracking executionnumber(optional) - Execution priority (lower = higher priority)front(optional) - If true, prioritize this executionextra_data(optional) - Additional metadataclient_id(optional) - WebSocket client identifierpartial_execution_targets(optional) - Array of specific nodes to execute
Node Structure
Each node in the prompt is keyed by a numeric string ID and contains:
class_type(required) - The ComfyUI node class nameinputs(required) - Input values or connections to other nodes_meta(optional) - Metadata not used in execution
Input Types
Node inputs can be:
- Direct values:
"text": "hello world" - Node connections:
"clip": ["1", 0](node_id, output_slot)
🛠️ Validation
Python Integration
from api_schemas.validation import validate_prompt_format
data = {"prompt": {...}}
is_valid, error_msg = validate_prompt_format(data)
if not is_valid:
print(f"Validation failed: {error_msg}")
Server-Side Validation
Enable validation with query parameter:
POST /prompt?validate_schema=true
Returns 400 Bad Request with detailed error information if validation fails.
🔧 Development
Requirements
For validation features:
pip install jsonschema
Schema Updates
When updating the schema:
- Modify
prompt_format.json - Test with real ComfyUI workflows
- Update examples and documentation
- Verify backward compatibility
Testing
# Test schema loading
from api_schemas.validation import load_prompt_schema
schema = load_prompt_schema()
assert schema is not None
# Test validation
from api_schemas.validation import validate_prompt_format
valid_prompt = {"prompt": {"1": {"class_type": "TestNode", "inputs": {}}}}
is_valid, error = validate_prompt_format(valid_prompt)
assert is_valid
📚 Examples
Basic Text-to-Image Workflow
{
"prompt": {
"1": {
"class_type": "CheckpointLoaderSimple",
"inputs": {
"ckpt_name": "model.safetensors"
}
},
"2": {
"class_type": "CLIPTextEncode",
"inputs": {
"text": "a beautiful landscape",
"clip": ["1", 1]
}
},
"3": {
"class_type": "CLIPTextEncode",
"inputs": {
"text": "blurry, low quality",
"clip": ["1", 1]
}
},
"4": {
"class_type": "KSampler",
"inputs": {
"seed": 12345,
"steps": 20,
"cfg": 7.0,
"sampler_name": "euler",
"scheduler": "normal",
"denoise": 1.0,
"model": ["1", 0],
"positive": ["2", 0],
"negative": ["3", 0],
"latent_image": ["5", 0]
}
},
"5": {
"class_type": "EmptyLatentImage",
"inputs": {
"width": 512,
"height": 512,
"batch_size": 1
}
},
"6": {
"class_type": "VAEDecode",
"inputs": {
"samples": ["4", 0],
"vae": ["1", 2]
}
},
"7": {
"class_type": "SaveImage",
"inputs": {
"filename_prefix": "ComfyUI",
"images": ["6", 0]
}
}
}
}
Partial Execution
{
"prompt": {
"1": {"class_type": "LoadImage", "inputs": {"image": "input.png"}},
"2": {"class_type": "SaveImage", "inputs": {"images": ["1", 0]}}
},
"partial_execution_targets": ["2"],
"prompt_id": "550e8400-e29b-41d4-a716-446655440000"
}
🤝 Contributing
This schema implementation addresses GitHub issue #8899.
To contribute:
- Test with real ComfyUI workflows
- Report issues or inaccuracies
- Suggest improvements for better IDE support
- Help with documentation and examples
📄 License
This follows the same license as ComfyUI main repository.