ComfyUI Node

Number Clamp

Keep your numbers between the lines

By DebugPadawan·Created about a year ago·Updated 5 months ago· 2
Number Clamp
    • clamped
    value0.00
    min_val0.00
    max_val1.00

    Every value in your workflow has a range it's supposed to live in. Number Clamp is the guardrail: it takes any number and squeezes it into a min/max window. Go over the top, and you get the max. Go under the bottom, and you get the min. It's the difference between a CFG slider that silently does something stupid at 22 and one that quietly stops at 12.

    It comes from DebugPadawan's ComfyUI Essentials, a small pure-Python utility pack. No models, no GPU, nothing heavy - this is just a polite max(min_val, min(value, max_val)) in a node wrapper.

    How it works

    The mechanism is dead simple and worth knowing exactly because it's so easy to assume wrong: it's max(min_val, min(value, max_val)). That's the standard clamp. Three inputs, all FLOATs:

    • value - the number to constrain (default 0)
    • min_val - the floor (default 0)
    • max_val - the ceiling (default 1)

    One output: clamped (FLOAT). The default of 0–1 is a nice hint at the most common use - anything that wants a normalized 0-to-1 value.

    Where you'll reach for it

    The classic ComfyUI clamps:

    • CFG and denoise. KSampler inputs are already bounded in the UI, but when those values come from other nodes - a random generator, a remap, a slider wired from somewhere else - they can escape. Clamp the line feeding your KSampler and you never get a "CFG 47" surprise.
    • RGB / color math. The README's own example: color values that must stay in 0–255. A strength that must stay in 0–1. A weight that must stay in 0–2. Clamp is the "make sure it's valid" step between a math node and a consumer that doesn't tolerate outliers.
    • Percentages and ratio math where a computed value can dip below 0 or blow past 100.

    It composes well with the rest of the pack - Number Remap then Number Clamp is a very common pairing, since remaps can push values outside their source range when the input is out of bounds.

    Installing it

    The pack installs once and gives you all its nodes. ComfyUI Manager, searching for "DebugPadawans-ComfyUI-Essentials," or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/DebugPadawan/DebugPadawans-ComfyUI-Essentials
    

    Then restart ComfyUI. Its requirements.txt (numpy, torch, opencv-python) is already satisfied by a stock ComfyUI install, and there are no model downloads. One naming trap: "DebugPadawan's ComfyUI Essentials" is a different, much smaller pack than cubiq's "ComfyUI Essentials," which went into maintenance mode - don't mix up the two when searching.

    The one gotcha

    If you set min_val higher than max_val, the clamp doesn't complain - it just returns min_val forever, because max(min_val, ...) always wins. That's a silent bug that can have you scratching your head for a while. If your clamped output stops changing, check your min/max aren't inverted. Also note it always returns a FLOAT; a node expecting an INT needs a conversion in between.

    CategoryDebugPadawan/Number

    Inputs (3)

    NameTypeDefaultDescription
    valueFLOAT0.00
    min_valFLOAT0.00
    max_valFLOAT1.00

    Outputs (1)

    NameTypeDescription
    clampedFLOAT