Merge Caption Tokens
Merge Two Caption Sources Into One Clean, De-Duplicated Line
- string
When you're assembling training captions - or a prompt to feed a model - you rarely have one source. There's the tagger output, there's your handwritten notes, there's the prompt text you already used, and they overlap. Bolt them together naively and you get masterpiece, 1girl, masterpiece, long hair with duplicates everywhere. IPT-MergeCaptionTokens is the de-dup pass: it takes a start string and an end string, splits both into tokens, drops any token that already appeared, and rebuilds a single clean caption.
It's one of three caption-adjacent nodes in this pack (with Remove Caption Tokens and Normalize Prompt Tokens), and it slots directly into the pack's caption-writing story - the same .txt caption files Image Saver writes beside images, the same format training pipelines expect.
How it works
The rule is deliberately simple and predictable. Caption tokens are split on , (comma-space) and . (period-space). The start text comes first, then end tokens that aren't already in the set, preserving order throughout. First occurrence wins - so if "long hair" appears in both, only the start copy survives. It then rejoins everything into a single comma-separated line. That means ordering is deterministic: whatever you put in start leads, end fills in the gaps, and nothing is duplicated no matter how much overlap you feed it.
Inputs and outputs
start(optional, STRING) - caption token text placed at the beginning.end(optional, STRING) - appended after start, minus duplicates.string(output, STRING) - the merged caption.
Both inputs are forced-input style and optional - leave one unconnected and the other passes through (de-duplicated against nothing). Wire the output straight into an Image Saver caption input or a caption-file node.
Installing it
Part of the kinorax/comfyui-info-prompt-toolkit pack:
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
The split only happens on comma-space and period-space. If your input uses commas without spaces (1girl,long hair) or some other separator, those become single tokens, and "de-duplication" won't catch near-duplicates like 1girl vs 1girl written differently. Also, because splitting is exact, long hair and long hair, are different tokens until trimming happens - the tooltips note token splitting on those two delimiters, so feed it reasonably clean text. It's not a fuzzy matcher, it's a set operation; think of it as "remove exact repeats while keeping order" and you'll never be surprised.
If you want to strip emphasis syntax or weights from prompt text before captioning, that's the pack's separate flattening node (Flatten Prompt for Caption) - this node assumes you've already got the token text you actually want.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| startopt | STRING | Caption token text placed at the beginning. Duplicates are removed after splitting on ', ' and '. '. | |
| endopt | STRING | Caption token text appended after start. Duplicates are removed after splitting on ', ' and '. '. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| string | STRING | — |