Xor
The boolean node for 'exactly one, never both'
- xor
Most people never need a node that outputs true only when its two inputs disagree. Then, one day, you're building a workflow where two things are mutually exclusive - "run the inpaint pass if a mask is loaded or a reference image is present, but not both" - and you realize plain And and Or can't say that. That's what Xor is for.
It's part of ComfyUI-BooleanExpression, Marco Zanella's zero-dependency logic pack. The name comes straight from logic gates: exclusive-or. True when exactly one input is true, false when both match (either both true or both false).
How it works
The inputs:
- first - "The first boolean value." Defaults to true.
- second - "The second boolean value." Defaults to true.
The source is revealingly simple: return (first != second,). That's the whole trick - Python's inequality test on booleans is exclusive-or. Two booleans differ exactly when one is true and the other isn't.
The output is named xor, a single BOOLEAN. It wires into the pack's Conditional Branch, the And/Or/Xor/Not group, or any other BOOLEAN input - same contract as every node in this pack.
The honest take on when you need it
Ninety-five percent of conditional workflows run on And and Or. Xor earns its slot for the mutual-exclusion pattern, which comes up more than you'd expect once you start automating:
- Optional-input guards. Only apply a two-pass pipeline when one of two optional inputs is present, not when both (or neither) are. This is the same "bypass if not loaded" problem people post about on r/comfyui constantly.
- Mode selectors. Two toggles that must never both be on - "upscale" and "do not upscale" as separate checkboxes is a UX mistake; Xor catches it.
- Setting swaps. A value should change exactly when a condition flips; feeding the xor of two toggles into a branch does that cleanly.
Be honest with yourself, though: if you can't name a use for it right now, you probably don't need it today. Keep it in the back of your head for the day a "must be one or the other" requirement shows up, because that's the day you'll be glad the pack ships it rather than making you stack a Nand and an Or by hand. (Not that you can't - but why would you?)
Install
It ships in the same pack as everything else here. ComfyUI Manager: search ComfyUI-BooleanExpression, install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/marco-zanella/ComfyUI-BooleanExpression.git
Restart ComfyUI; it's under Boolean Expressions, alongside And, Or, Nand, and Nor. The pack is pure Python with an empty requirements.txt - no pip dependencies, no model downloads - and it's on the Comfy Registry so Manager resolves it by title.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| first | BOOLEAN | true | The first boolean value. |
| second | BOOLEAN | true | The second boolean value. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| xor | BOOLEAN | — |