Nodes/WAS Node Suite v3/Text String Truncate
ComfyUI Node Runs on cloud

Text String Truncate

Chop a string down to size, from either end

By WASasquatch·Created 3 years ago·Updated 5 days ago· 1,844
Text String Truncate
    • TEXT
    • TEXT_B
    • TEXT_C
    • TEXT_D
    • TEXT_E
    • TEXT_F
    • TEXT_G
    • TEXT_H
    • TEXT_I
    • TEXT_J
    • TEXT_K
    • TEXT_L
    • TEXT_M
    • TEXT_N
    • TEXT_O
    • TEXT_P
    • TEXT_Q
    • TEXT_R
    • TEXT_S
    • TEXT_T
    • TEXT_U
    • TEXT_V
    • TEXT_W
    • TEXT_X
    truncate_by
    truncate_from
    truncate_to10
    text
    text_b
    text_c
    text_d
    text_e
    text_f
    text_g
    text_h
    text_i
    text_j
    text_k
    text_l
    text_m
    text_n
    text_o
    text_p
    text_q
    text_r
    text_s
    text_t
    text_u
    text_v
    text_w
    text_x

    Exactly what it says: it truncates a string, from the beginning or the end, by characters or by words. Nothing fancier than that, and that's the appeal - half the time you don't need clever text processing, you need to make sure a string doesn't blow past a length limit somewhere downstream.

    Where it actually earns its slot

    The obvious use is filenames. If you're building a save filename out of a truncated prompt or a caption, most filesystems (and your own sanity when browsing an output folder) start to hurt somewhere past a couple hundred characters. Feed your full prompt or a BLIP-generated caption through this node, cap it at a sane length, and hand the result to WAS's Save Text File or Save Image filename pattern instead of the raw string.

    The other case is anywhere a downstream node or model has an effective input limit - a CLIP text encoder's token budget, a caption overlay that only has room for one line, a title field in some other tool your workflow feeds into. Rather than manually keeping your prompt short, you write it long and let this node cut it down automatically before it reaches the limit.

    How it works

    You give it a string, and it cuts from either the front or the back, counting either in characters or in whole words. Character truncation is the blunt option - fast and predictable, but it can land you mid-word. Word truncation costs a little more precision over the exact length but keeps what's left readable, which matters if the truncated text is going to be displayed rather than just used as an internal identifier. The output is a single truncated string, and it slots in anywhere a text input goes - another Text Concatenate, a Save node, a second Truncate node if you need to cut from both ends.

    Installing it

    This is one node out of the whole WAS Node Suite pack - you don't install it separately:

    • ComfyUI Manager - search WAS Node Suite, install, restart.
    • Manual - cd ComfyUI/custom_nodes && git clone https://github.com/WASasquatch/was-node-suite-comfyui/, then pip install -r requirements.txt from inside that folder (or the portable build's embedded python equivalent), then restart ComfyUI.

    Common issues

    Nothing specific to this node tends to go wrong beyond the obvious: truncating by character can slice a word in half, which looks sloppy in a filename or a displayed caption - switch to word-based truncation if that's a problem for you, at the cost of the exact length no longer being guaranteed.

    The pack-wide issue to know about going in: WAS Node Suite hasn't been actively developed since December 2023, and the most common symptom of that is an "Import Failed" error after a ComfyUI update, because the pack's pinned dependencies can drift out of sync with what a newer ComfyUI or a sibling custom node expects. If that happens, reinstalling requirements.txt inside your ComfyUI venv is usually the fix; it's a real, recurring complaint in the community, not a one-off.

    CategoryWAS Suite/Text/Operations

    Inputs (27)

    NameTypeDefaultDescription
    truncate_byCOMBOWhat truncate_to counts. `characters` counts single characters, spaces included. `words` counts whitespace-separated words and rejoins them with one space each, so line breaks and runs of spaces in the text collapse.
    truncate_fromCOMBOWhich end of the text is kept. `end` keeps the tail and throws the start away, so 'a long prompt' truncated to 6 characters becomes 'prompt'. `beginning` keeps the head, giving 'a long'.
    truncate_toINT10-99999999–99999999How much to keep, counted in characters or words. A negative value measures what to remove instead: with truncate_from `end`, -10 keeps everything except the last 10, and with `beginning`, -10 keeps only the last 10. Zero with `end` keeps everything, and zero with `beginning` empties the text.
    textSTRINGFirst text to shorten; STRING. Cut per truncate_by, truncate_from and truncate_to; leaves on TEXT.
    text_boptSTRINGSecond text; STRING. Same settings, leaves on TEXT_B.
    text_coptSTRINGThird text; STRING. Same settings, leaves on TEXT_C.
    text_doptSTRINGFourth text; STRING. Same settings, leaves on TEXT_D.
    text_eoptSTRINGText 5, emitted on its own output. Tokens are substituted.
    text_foptSTRINGText 6, emitted on its own output. Tokens are substituted.
    text_goptSTRINGText 7, emitted on its own output. Tokens are substituted.
    text_hoptSTRINGText 8, emitted on its own output. Tokens are substituted.
    text_ioptSTRINGText 9, emitted on its own output. Tokens are substituted.
    text_joptSTRINGText 10, emitted on its own output. Tokens are substituted.
    text_koptSTRINGText 11, emitted on its own output. Tokens are substituted.
    text_loptSTRINGText 12, emitted on its own output. Tokens are substituted.
    text_moptSTRINGText 13, emitted on its own output. Tokens are substituted.
    text_noptSTRINGText 14, emitted on its own output. Tokens are substituted.
    text_ooptSTRINGText 15, emitted on its own output. Tokens are substituted.
    text_poptSTRINGText 16, emitted on its own output. Tokens are substituted.
    text_qoptSTRINGText 17, emitted on its own output. Tokens are substituted.
    text_roptSTRINGText 18, emitted on its own output. Tokens are substituted.
    text_soptSTRINGText 19, emitted on its own output. Tokens are substituted.
    text_toptSTRINGText 20, emitted on its own output. Tokens are substituted.
    text_uoptSTRINGText 21, emitted on its own output. Tokens are substituted.
    text_voptSTRINGText 22, emitted on its own output. Tokens are substituted.
    text_woptSTRINGText 23, emitted on its own output. Tokens are substituted.
    text_xoptSTRINGText 24, emitted on its own output. Tokens are substituted.

    Outputs (24)

    NameTypeDescription
    TEXTSTRINGThe shortened text.
    TEXT_BSTRINGThe shortened text_b.
    TEXT_CSTRINGThe shortened text_c.
    TEXT_DSTRINGThe shortened text_d.
    TEXT_ESTRINGText 5, with its tokens substituted.
    TEXT_FSTRINGText 6, with its tokens substituted.
    TEXT_GSTRINGText 7, with its tokens substituted.
    TEXT_HSTRINGText 8, with its tokens substituted.
    TEXT_ISTRINGText 9, with its tokens substituted.
    TEXT_JSTRINGText 10, with its tokens substituted.
    TEXT_KSTRINGText 11, with its tokens substituted.
    TEXT_LSTRINGText 12, with its tokens substituted.
    TEXT_MSTRINGText 13, with its tokens substituted.
    TEXT_NSTRINGText 14, with its tokens substituted.
    TEXT_OSTRINGText 15, with its tokens substituted.
    TEXT_PSTRINGText 16, with its tokens substituted.
    TEXT_QSTRINGText 17, with its tokens substituted.
    TEXT_RSTRINGText 18, with its tokens substituted.
    TEXT_SSTRINGText 19, with its tokens substituted.
    TEXT_TSTRINGText 20, with its tokens substituted.
    TEXT_USTRINGText 21, with its tokens substituted.
    TEXT_VSTRINGText 22, with its tokens substituted.
    TEXT_WSTRINGText 23, with its tokens substituted.
    TEXT_XSTRINGText 24, with its tokens substituted.