Clamp
Put a Fence Around a Number So It Can't Go Off the Rails
- value
- min_value
- max_value
- MATCHTYPE
UC_MathClamp pins a number inside a minimum and maximum: anything below the floor gets pulled up to it, anything above the ceiling gets pulled down, and everything in between passes through untouched. It's the "safety rails" node, and in ComfyUI you'll want it the first time an AI-generated parameter value goes somewhere you didn't expect.
Why you'd reach for it
The most honest use case is defense. When a value is computed by a chain of math - a denoise strength derived from a slider and a formula, a CFG scaled by something a text node spat out - it can land outside the range your sampler or widget can tolerate. A clamp guarantees it stays between, say, 0 and 1 for denoise, or 1 and 30 for CFG, no matter what upstream does. That one node can be the difference between a workflow that "randomly" errors and one that quietly works. It's also the mechanism behind a lot of normalizations: if you want a value in [0, 1] but not scaled, clamping is the blunt version and sometimes exactly what you need.
How it works
The implementation is the classic nested form: max(min(value, max_value), min_value). Three inputs - value, min_value, max_value - all accepting int or float, and the output carries the same type as the input. The nested order means it degrades gracefully even if you accidentally wire min_value larger than max_value: instead of erroring, it just returns the tighter bound, which is friendlier than the alternative.
The inputs that matter
value- what you're fencing in.min_valueandmax_value- the floor and ceiling.
Everything else is one output, ready to feed the widget or node that needed the bounded number.
Installing it
Ships in ComfyUI-UtilsCollection. ComfyUI Manager → search "ComfyUI-UtilsCollection" → Install → restart, or:
cd ComfyUI/custom_nodes
git clone https://github.com/silveroxides/ComfyUI-UtilsCollection
Restart. No models involved; the pack's requirements are just opencv-python and typing-extensions.
What to watch for
The one habit worth building: clamp after you've done your math, not before. Clamping an already-clamped pipeline is harmless but pointless, and it can hide a bug in the upstream formula you'd rather see. Also - this is a replacement for the old ComfyUI-LogicMath clamp, so if you're migrating, let ComfyUI swap the old node and then uninstall LogicMath. If a workflow starts complaining about duplicate nodes, that's the first suspect. Clamp won't win any awards for excitement, but it's one of those nodes that quietly prevents the workflow from being the thing that wastes your evening.
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 | — |