Nodes/comfyui-prompt-library-nodes/Prompt Aspect Latent Router
ComfyUI Node

Prompt Aspect Latent Router

Prompt Aspect Latent Router

By 2223290690z-hue·Created 3 months ago·Updated 2 months ago· 1
Prompt Aspect Latent Router
    • LATENT
    • STRING
    string
    default_aspectlandscape
    batch_size1

    You know the ritual: an EmptyLatentImage node sits there with width and height baked in, and every time you decide the scene is really a portrait, you go nudge two numbers. This node from comfyui-prompt-library-nodes does the opposite - you put an aspect tag like [portrait] in the prompt text itself, and the node makes a latent in that shape while stripping the tag out before it reaches the CLIP encoder. The prompt drives the canvas, not the other way around.

    It's the one node in this pack that actually touches latents; the rest are prompt-plumbing. It's genuinely handy once you get the habit of writing [landscape] or [square] at the start of a prompt, because the aspect hint travels with the prompt - which means it also travels with the workflow JSON and any notes you share, instead of hiding in a widget nobody reads.

    How it works

    The mechanism is almost embarrassingly simple. It scans the prompt text for the first bracket tag matching one of five known aspects, creates an empty latent at the matching size with torch.zeros, and deletes the tag from the string:

    | Tag | Size | | --- | --- | | [story] | 768 x 1344 | | [portrait] | 832 x 1216 | | [square] | 1024 x 1024 | | [banner] | 1536 x 640 | | [landscape] | 1216 x 832 |

    First tag found wins. No tag found? It falls back to default_aspect, which is landscape by default. Then it hands you a clean prompt with no tag and a fresh latent of the right shape.

    The LATENT output goes into your KSampler, the STRING output goes into the positive CLIPTextEncode. That's the whole loop - nothing downstream can tell the difference from an EmptyLatentImage, except the size was decided by text.

    The inputs that matter

    • string - the prompt text with an optional aspect tag. You can type it or wire it from another node.
    • default_aspect - what to use when the prompt has no tag. Set this to your most common format and only tag the exceptions.
    • batch_size - how many latents to create, 1 to 64. Match it to the batch you want to sample.

    One quirk worth knowing, straight from the source: the enum also offers iPhone 12 mini (768 x 1664) as a default, but the tag-detection regex only recognizes [story], [portrait], [square], [banner], and [landscape]. So [iPhone 12 mini] typed in the prompt will never be found or stripped - you can only get that size by selecting it as the default. Minor, but it'll confuse you exactly once.

    Installing it

    This pack has zero dependencies - no requirements.txt, nothing to pip. Just ComfyUI's built-in folder_paths/comfy APIs and torch, which you already have. Easiest route: ComfyUI Manager → search "comfyui-prompt-library-nodes" → install → restart. Or clone it by hand:

    cd ComfyUI/custom_nodes
    git clone https://github.com/2223290690z-hue/comfyui-prompt-library-nodes.git
    

    Then restart ComfyUI. You'll find the node as Prompt Aspect Latent Router in the utils/prompt category.

    Troubleshooting

    • The tag is still in the prompt - check the spelling. The regex is case-insensitive but the tag must match one of the five above; [portrait] works, [portrait ] with a space doesn't.
    • Nothing renders as the default - you set default_aspect and didn't put a tag in the string, which is correct behavior, just easy to mistake for a bug.
    • Empty or stale previews elsewhere in this pack - not this node's problem; that's the frontend preview helper, and it refreshes when you touch a widget.

    This isn't a flashy node, and it doesn't need to be. It removes a couple of fiddly widget edits from every run and makes your aspect intent readable in the prompt itself. For a pack that's otherwise all about keeping prompt material out of the graph, it's the cleanest idea in the repo.

    Categoryutils/prompt

    Inputs (3)

    NameTypeDefaultDescription
    stringSTRING
    default_aspectCOMBOlandscape6 options: story, portrait, square, banner, landscape, iPhone 12 mini
    batch_sizeINT11–64

    Outputs (2)

    NameTypeDescription
    LATENTLATENT
    STRINGSTRING