Nodes/DJZ-Nodes/Prompt Inject
ComfyUI Node

Prompt Inject

Surgically slipping words into the middle of a prompt

By MushroomFleet·Created 2 years ago·Updated 5 months ago· 77
Prompt Inject
    • STRING
    text
    targetthe scene is captured
    injectionScreeching tires.

    Every prompt chain eventually has this problem: you've got a long prompt built by other nodes, and you want to add one phrase in the middle of it - not append it, not prepend it, but drop it right before a specific clause. Hand-editing works until the source prompt is generated by something else, at which point you need a node. That's PromptInject: a tiny string surgery tool that finds a target phrase and shoves your injection directly in front of it.

    Three inputs, one output. text (multiline) is your full prompt, target is the phrase to locate - the default is the scene is captured, which tells you who wrote this and for what kind of prompt - and injection is what gets inserted before it. The default injection is Screeching tires. because this was built for video-style prompts where a scene description ends with a camera phrase and you want to bolt on an action beat. Output is a single STRING, ready to wire into a CLIP Text Encode.

    The mechanism is honestly just a regex find-and-replace, but a few details make it feel polished. Matching is case-insensitive, so The scene is captured and the scene is captured both hit. The injection is auto-wrapped with spaces, and if it ends in punctuation (., !, ?) it gets exactly one trailing space - so Screeching tires. lands as ...where Screeching tires. the scene is captured... without you fighting whitespace. There's a log line written on every run so you can see the before/after.

    Two things to know before you use it. First, it injects before the target and only the first occurrence - if your target phrase appears twice, you only get one shot. Keep target specific. Second, and this is the part people miss: if the target isn't found, the node still returns your text, just unmodified. There's no error, no flag. So if your injection silently never appears, your target string drifted - check the exact phrasing rather than assuming the node broke.

    Why bother? Because injection keeps your prompt architecture composable. If you've got a base scene prompt that other nodes (wildcards, an LLM prompt builder, a caption loader) produce dynamically, injecting at a known anchor phrase is far more robust than trying to concatenate onto a string whose ending you don't control. The SDXL-era habit of comma-tag prompts makes this less useful for booru-style tags - it shines on the sentence-structured, camera-describing prompts that newer LLM-encoded models actually reward (naming the camera and the moment is high-leverage there).

    One honest caveat: PromptInject is the V1 of a two-node pair. The only real thing V2 adds is inject_after, letting you place the text after the target instead of before. If you only ever want "before," this version is all you need and there's no reason to chase V2; if you might want both sides, grab PromptInjectV2 and skip this one.

    CategoryCustom-Nodes

    Inputs (3)

    NameTypeDefaultDescription
    textSTRING
    targetSTRINGthe scene is captured
    injectionSTRINGScreeching tires.

    Outputs (1)

    NameTypeDescription
    STRINGSTRING