Nodes/ComfyUI-Info-Prompt-Toolkit/Normalize Prompt Tokens
ComfyUI Node

Normalize Prompt Tokens

Beat Your Prompt Into Consistent, Tagger-Style Shape

By kinorax·Created 5 months ago·Updated about a month ago· 2
Normalize Prompt Tokens
    • string
    string

    Prompts come in from all sorts of places - hand-typed, pasted from a web page, yanked out of a metadata block - and they rarely arrive tidy. Newlines in the middle, full-width spaces, 1girl,long hair with no space after the comma, trailing commas, double spaces where someone's editor did something weird. Most of the time it doesn't matter. The moment you're feeding that text to a caption pipeline, a tagger, or a training dataset, it matters a lot. IPT-NormalizePromptTokens scrubs a prompt into consistent tagger-style form: commas and periods get a space after them, newlines become commas, runs of spaces collapse, and trailing commas vanish.

    Think of it as the "make this text look like it came from a WD14 tagger" pass. The pack's whole caption story depends on predictable token text - Merge Caption Tokens and Remove Caption Tokens split on , and . , and if your input has inconsistent spacing, those exact-match operations miss. Normalizing first is what makes the rest of the chain behave.

    How it works

    The transformation list, from the source: full-width spaces become normal spaces; leading/trailing whitespace is stripped; newlines collapse into commas; commas without a following space get one inserted; same for periods; consecutive spaces collapse to one; space-before-comma/period cases are fixed; and trailing commas are removed. It treats the text as a token list - non-structured text - so it's not parsing grammar, it's enforcing a uniform delimiter style. Output is a single clean string.

    Inputs and outputs

    • string (optional, STRING) - the prompt text to normalize. Forced-input style, so wire it from anywhere.
    • string (output, STRING) - the normalized result.

    Installing it

    Standard pack install:

    cd ComfyUI/custom_nodes
    git clone https://github.com/kinorax/comfyui-info-prompt-toolkit.git
    cd comfyui-info-prompt-toolkit
    pip install -r requirements.txt
    

    Restart, or ComfyUI Manager → "ComfyUI-Info-Prompt-Toolkit". ComfyUI 0.17.0+. No models.

    Common issues

    It normalizes delimiters, not vocabulary. It won't spellcheck, won't merge synonyms, and won't fix 1girl,long hair into 1girl, long hair differently than the rule above does - actually it will add the space, that's the point - but it won't turn long_hair into long hair. If you need token-level cleaning beyond spacing, chain it with the caption nodes in this pack. And note the output is plain text: it doesn't touch prompt emphasis syntax like (word:1.2) or <lora:...> tags, so if you're normalizing before writing training captions you may still want the pack's flattening node to strip weights first. For the common "tidy this up so downstream nodes agree on the format" job, it's exactly right.

    CategoryInfo-Prompt-Toolkit/Prompt

    Inputs (1)

    NameTypeDefaultDescription
    stringoptSTRINGPrompt text treated as token list (non-structured text)

    Outputs (1)

    NameTypeDescription
    stringSTRING