← Về thư mục
📄 / / root / .hermes / profiles / glv-director / skills / creative / comfyui / references / template-integrity.md

ComfyUI Workflow-Template Integrity

Authored by @purzbeats — adapted from purzbeats/hermes-agent-comfyui-helper. Use this reference when converting workflows from the official comfyui-workflow-templates package (editor format) into API format for submission via /api/prompt. The conversion has subtle gotchas that cause hard-to-diagnose validation errors if you don't follow these rules.

Background

The official ComfyUI template package (comfyui-workflow-templates, currently v0.9.69) is installed inside the ComfyUI venv at a path like:

<comfy-install>/.venv/lib/python3.*/site-packages/comfyui_workflow_templates_*/templates/

The exact path depends on how ComfyUI was installed (comfy-cli default, Comfy Desktop, manual venv, etc.). Find it once with:

comfy --workspace <ws> run-python -c "import comfyui_workflow_templates, pathlib; print(pathlib.Path(comfyui_workflow_templates.__file__).parent / 'templates')"

Templates ship in editor formatnodes / links arrays inside data['definitions']['subgraphs'][0]. They must be converted to API format (a node_id -> {class_type, inputs} mapping) before submission.


RULE #1: Use templates AS CLOSE TO ORIGINAL AS POSSIBLE

RULE #2: Server validation errors are the source of truth

When a workflow submission fails, the server response looks like:

{
  "node_errors": {
    "238": {
      "errors": [{
        "message": "Required input is missing",
        "details": "width",
        "extra_info": { "input_name": "resize_type.width" }
      }]
    }
  }
}

The extra_info.input_name field tells you EXACTLY what JSON key the server wants. Use it literally. If it says "values.a" or "resize_type.width", those are the actual key names in the JSON object. Do not "simplify" them to flat names based on assumptions about what the field "should" be called.

RULE #3: Don't rebuild from scratch — patch the failing nodes

Every regeneration from the template reintroduces the same bugs. Instead:

  1. Submit the workflow once.
  2. Read the server error details for exact key names.
  3. Use targeted patch/fix calls against the workflow file on disk.
  4. Resubmit and check if errors resolved.

Reroute nodes: bypass, don't delete

Most servers (local, Cloud) don't have a Reroute node type. When converting a template:

  1. Find what feeds into the Reroute by looking at links where target_id = the Reroute node ID.
  2. Replace all inputs referencing the Reroute with [source_node_id, source_slot].
  3. Delete the Reroute node from the API mapping.

Real example — LTX 2.3 t2v template:

❌ Wrong vae: ["236", 0]MODELV mismatch input_type(VAE)
✅ Correct vae: ["236", 2]

Dynamic template nodes: dotted key names are correct

ComfyMathExpression (COMFY_AUTOGROW_V3)

{
  "class_type": "ComfyMathExpression",
  "inputs": {
    "expression": "a/2",
    "values.a": ["257", 0]
  }
}

ResizeImageMaskNode (COMFY_DYNAMICCOMBO_V3)

{
  "class_type": "ResizeImageMaskNode",
  "inputs": {
    "input": ["276", 0],
    "scale_method": "lanczos",
    "resize_type": "scale dimensions",
    "resize_type.width": 1920,
    "resize_type.height": 1088,
    "resize_type.crop": "center"
  }
}

Conversion recipe

  1. Load template from the installed package path.
  2. Parse data['definitions']['subgraphs'][0].
  3. For each node (skip Reroute):
  4. Resolve linked inputs from sg['links'] dict.
  5. Map widgets_values to input field names.
  6. Keep all dotted key names as-is from the template.
  7. Bypass Reroute: trace source, replace references.
  8. Change only: prompt text, seed values, and user-requested parameters.
  9. Add SaveVideo terminal node if template uses only CreateVideo.
  10. Submit → read errors → patch specific nodes → resubmit.

What to NEVER change in a template

Element Why
Node topology Graph is designed for the specific model
Sigmas values Tuned for the model/sampler combination
LoRA/distilled paths Required for quality, even if they look unused
Model parameters (cfg, steps, shifts) Model-specific
Conditioning chains (zero-out, crop guides) Required for correct conditioning
Pass-through wiring Don't remove nodes, bypass them

Cloud compatibility (verified May 2025)

The full LTX 2.3 T2V template (video_ltx2_3_t2v.json) runs without modification on Comfy Cloud.

Confirmed working on Cloud (all custom nodes available): ComfyMathExpression, ResizeImageMaskNode, ResizeImagesByLongerEdge, PrimitiveInt, PrimitiveStringMultiline, PrimitiveBoolean, SaveVideo, LTXVCropGuides, LTXVImgToVideoInplace, LTXVConcatAVLatent, LTXVSeparateAVLatent, LTXVLatentUpsampler, LTXVAudioVAELoader, LTXVAudioVAEDecode, LTXVEmptyLatentAudio, LTXVPreprocess, LTXVConditioning, ManualSigmas, LTXAVTextEncoderLoader, plus all core nodes.

Cloud vs Local for LTX 2.3 (768x512):

Cloud submission pitfalls:


FFmpeg stitch settings (Discord-compatible)

Generated ComfyUI videos often use yuv444p pixel format which does NOT work on Discord. Re-encode with:

ffmpeg -y -i input.mp4 \
  -c:v libx264 -profile:v main -preset medium -crf 13 -pix_fmt yuv420p \
  -c:a aac -b:a 192k \
  output_discord.mp4

Key settings:

For multi-video crossfade stitching, chain xfade (video) and acrossfade (audio):

ffmpeg -y -i a.mp4 -i b.mp4 -i c.mp4 \
  -filter_complex "[0:v][1:v]xfade=transition=fade:duration=1:offset=3.04[v1];[v1][2:v]xfade=transition=fade:duration=1:offset=6.08[vout];[0:a][1:a]acrossfade=duration=1:c1=tri:c2=tri[a1];[a1][2:a]acrossfade=duration=1:c1=tri:c2=tri[aout]" \
  -map "[vout]" -map "[aout]" \
  -c:v libx264 -profile:v main -crf 13 -pix_fmt yuv420p \
  -c:a aac -b:a 192k \
  output.mp4

Offset for xfade #N = (N+1) × duration - N × overlap.