feat(api): add /validate_prompt endpoint for pre-execution validation #9478
+37
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #9076
This pull request introduces a new API endpoint,
validate_prompt
, to validate the structure and integrity of a ComfyUI workflow prompt without executing it.What does this PR do?
POST /validate_prompt
endpoint that accepts a JSON workflow prompt.- Missing required input for all nodes.
- Invalid values (e.g.
ckpt_name
that doesn't exist).- Incorrectly linked nodes or data types.
"valid": true
for a correct prompt or"valid": false
along with anode_erros
object detailing the specified issues.Why is this change needed?
Currently, the only way to know if a prompt is valid is to queue it for execution. This is inefficient for both the client and server. This new endpoint provides a quick, lightweight method to pre-validate prompts, improving the user experience and reducing the server load from failed runs.
Testing & Verification
The endpoint has been tested for both valid and invalid workflow scenarios using Postman.
Valid Workflow Response
Below is the Postman screenshot showing successful for a correctly structured workflow. The API returns
200 OK
with"valid": true
.Invalid Workflow Response
To ensure robust error handling, an invalid workflow was tested by removing the required
positive
input from theKSampler
node. The API correctly identifies the error, returning a400 Bad Request
with"valid": false
and a detailed error message.