Clamp
Keep a value inside a range, no Max/Min chain
- value
- min_value
- max_value
- MATCHTYPE
Clamp is the "keep this number on the rails" node: it takes a value and squeezes it into a min_value to max_value range, hard. Below the min it returns the min, above the max it returns the max, in between it passes through unchanged. It's what you'd otherwise build from a Max and a Min wired in series, compressed into one node.
This is one of the most practically useful math nodes in the pack, because ComfyUI workflows are full of values that can drift out of range and break things. Denoise strength, CFG scale, LoRA weights, upscale factors, batch sizes - feed any of them into a Clamp and you get a hard guarantee they stay in the band a downstream node can handle. If a computed strength sometimes lands at 1.4 when the consumer only accepts up to 1.0, Clamp is the one-node fix. It's also the honest way to express "always within this window" in a graph you plan to share, because the intent is visible at a glance.
How it works
The mechanism is Python's max(min(value, max_value), min_value) - clamp to the max first, then to the min - wrapped in a node. All three inputs accept ints or floats via the type template, and the output type follows the input. The result is guaranteed to satisfy min_value <= result <= max_value whenever the range is sane.
One caveat to keep in mind: keep min_value less than or equal to max_value. If you feed it an inverted range (min above max), the math does something, but what it does is probably not what you wanted - the output collapses toward the min and the result stops behaving like a clamp. A quick sanity check on your bounds beats debugging a mysteriously stuck output.
The inputs that matter
value- the number to constrain.min_value- the floor; outputs below this get pulled up to it.max_value- the ceiling; outputs above this get pulled down to it.
Output is the clamped value, a MATCHTYPE number.
Install
This node ships in the ComfyUI-LogicMath pack. Install via ComfyUI Manager (search "ComfyUI-LogicMath", Install, restart) or:
cd ComfyUI/custom_nodes
git clone https://github.com/silveroxides/ComfyUI-LogicMath
No pip dependencies, no model downloads. The pack uses ComfyUI's newer extension API, so update ComfyUI if the node doesn't show up.
Common issues
- Output stuck at a fixed number - check whether min and max got inverted; with min > max the clamp collapses and the output stops tracking the input.
- Value not clamped at all - the input was already inside the range; that's correct behavior, not a failure.
Clamp is the rare "safety" node that also reads well in a shared workflow - anyone who opens your graph can see the bounds at a glance. If you only add one range-guard node to your toolkit, this is the one.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| value | COMFY_MATCHTYPE_V3 | — | |
| min_value | COMFY_MATCHTYPE_V3 | — | |
| max_value | COMFY_MATCHTYPE_V3 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MATCHTYPE | COMFY_MATCHTYPE_V3 | — |