ComfyUI is sometimes described as node-based programming, but at its simplest it is a straight path: put a model and prompts into KSampler, and an image comes out.
Still, sometimes you want to build a slightly more complex pipeline.
- If the input image is small, insert an upscale step.
- Analyze the image, and if the hands look broken, add a post-processing step.
- If the prompt contains certain text, switch to a different model or setting.
- ...
In programming, this kind of "change the process depending on a condition" is called conditional branching. ComfyUI also has basic nodes that let you do something close to this.
Conditional Branching Basics

{
"id": "29ed44dd-6fe2-456a-bd1a-461f34951fde",
"revision": 0,
"last_node_id": 8,
"last_link_id": 8,
"nodes": [
{
"id": 3,
"type": "LoadImage",
"pos": [
2748.9669779761944,
1624.9274767201969
],
"size": [
226.7833983976825,
326
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
3
]
},
{
"name": "MASK",
"type": "MASK",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"B.png",
"image"
]
},
{
"id": 2,
"type": "LoadImage",
"pos": [
2492.7754310784335,
1498.5904319414708
],
"size": [
226.7833983976825,
326
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
1
]
},
{
"name": "MASK",
"type": "MASK",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"A.png",
"image"
]
},
{
"id": 8,
"type": "PrimitiveBoolean",
"pos": [
2748.769003945466,
2005.3149857773456
],
"size": [
230.67001742550065,
58
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "BOOLEAN",
"type": "BOOLEAN",
"links": [
8
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PrimitiveBoolean"
},
"widgets_values": [
true
],
"color": "#432",
"bgcolor": "#653"
},
{
"id": 4,
"type": "PreviewImage",
"pos": [
3344.4342364224844,
1498.5904319414708
],
"size": [
304.55743368775256,
332.8579683361372
],
"flags": {},
"order": 4,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 4
}
],
"outputs": [],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PreviewImage"
},
"widgets_values": []
},
{
"id": 1,
"type": "ComfySwitchNode",
"pos": [
3040.914082203413,
1498.5904319414708
],
"size": [
270,
78
],
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"name": "on_false",
"type": "IMAGE",
"link": 1
},
{
"name": "on_true",
"type": "IMAGE",
"link": 3
},
{
"name": "switch",
"type": "BOOLEAN",
"widget": {
"name": "switch"
},
"link": 8
}
],
"outputs": [
{
"name": "output",
"type": "IMAGE",
"links": [
4
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "ComfySwitchNode"
},
"widgets_values": [
false
],
"color": "#232",
"bgcolor": "#353"
}
],
"links": [
[
1,
2,
0,
1,
0,
"IMAGE"
],
[
3,
3,
0,
1,
1,
"IMAGE"
],
[
4,
1,
0,
4,
0,
"IMAGE"
],
[
8,
8,
0,
1,
2,
"BOOLEAN"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 0.9229599817706482,
"offset": [
-2156.9237407065307,
-1178.4599104270771
]
},
"frontendVersion": "1.44.19"
},
"version": 0.4
}
Switching with Switch
The basic node for conditional branching is the Switch node.
It switches which of two inputs should be output.
With this, you can do things like output a when the condition matches, and output b when it does not.
Pass a Boolean to Switch
In Switch, the value that decides which of the two inputs to output is a Boolean.
A Boolean is a simple type that can only be true or false (0 or 1). It is like a toggle switch.
Of course, you can click it manually, but that is not very interesting.
Switching the process programmatically is basically about how to create this Boolean.
Ways to Create a Boolean
In programming, there are many ways to create a Boolean. Here, let's look at a few general-purpose methods available with ComfyUI core nodes.
Math Expression
As shown in Simple Math, this node can compare numbers and create a Boolean.
For example, write the following.

{
"id": "ff9a0a9c-3ced-4326-962a-7af275c3f71d",
"revision": 0,
"last_node_id": 3,
"last_link_id": 2,
"nodes": [
{
"id": 3,
"type": "PreviewAny",
"pos": [
3324.4682790386732,
1536.2539712098414
],
"size": [
210,
165.81084525752772
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [
{
"name": "source",
"type": "*",
"link": 2
}
],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PreviewAny"
},
"widgets_values": [
null,
null,
null
]
},
{
"id": 2,
"type": "PrimitiveInt",
"pos": [
2692.0190372490806,
1536.2539712098414
],
"size": [
246.3932026778166,
82
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "INT",
"type": "INT",
"links": [
1
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PrimitiveInt"
},
"widgets_values": [
20,
"fixed"
]
},
{
"id": 1,
"type": "ComfyMathExpression",
"pos": [
2981.095936608758,
1536.2539712098414
],
"size": [
300.68864574805593,
165.81084525752772
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [
{
"label": "a",
"name": "values.a",
"type": "FLOAT,INT,BOOLEAN",
"link": 1
},
{
"label": "b",
"name": "values.b",
"shape": 7,
"type": "FLOAT,INT,BOOLEAN",
"link": null
}
],
"outputs": [
{
"name": "FLOAT",
"type": "FLOAT",
"links": null
},
{
"name": "INT",
"type": "INT",
"links": null
},
{
"name": "BOOL",
"type": "BOOLEAN",
"links": [
2
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "ComfyMathExpression"
},
"widgets_values": [
"a == 20"
],
"color": "#232",
"bgcolor": "#353"
}
],
"links": [
[
1,
2,
0,
1,
0,
"INT"
],
[
2,
1,
2,
3,
0,
"BOOLEAN"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 1.2284597357367328,
"offset": [
-2415.4416212964616,
-1188.9216918748982
]
},
"frontendVersion": "1.44.19"
},
"version": 0.4
}
a == 20
Connect an int node that inputs a number such as 18 or 20 to a.
As you can see, it shows true only when the value is 20, the value you set.
You can also use more numbers and variables.
0 < a <= b * 100
With this expression, the result is true when a is greater than 0 and less than or equal to b * 100.
You can use comparison operators like these.
a == b # equal
a != b # not equal
a > b # a is greater than b
a >= b # a is greater than or equal to b
a < b # a is less than b
a <= b # a is less than or equal to b
Compare Text
To create a Boolean from text, use the Compare Text node.
It is very simple: it compares two strings and outputs the result as a Boolean.
For example, you can check whether the input text matches Hello, starts with Hello, or ends with Hello.

{
"id": "1db6b4f2-1dca-4383-93dc-766f6750bfc2",
"revision": 0,
"last_node_id": 6,
"last_link_id": 5,
"nodes": [
{
"id": 5,
"type": "PrimitiveString",
"pos": [
2668.412239926897,
1536.2539712098414
],
"size": [
270,
58
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": [
3
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PrimitiveString"
},
"widgets_values": [
"Hello World"
]
},
{
"id": 6,
"type": "PrimitiveString",
"pos": [
2668.412239926897,
1662.1432549853873
],
"size": [
270,
58
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": [
4
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PrimitiveString"
},
"widgets_values": [
"Hello"
]
},
{
"id": 3,
"type": "PreviewAny",
"pos": [
3324.4682790386732,
1536.2539712098414
],
"size": [
210,
190
],
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"name": "source",
"type": "*",
"link": 5
}
],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PreviewAny"
},
"widgets_values": [
null,
null,
null
]
},
{
"id": 4,
"type": "StringCompare",
"pos": [
2986.3871153189016,
1536.2539712098414
],
"size": [
290.1062883277673,
190
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [
{
"name": "string_a",
"type": "STRING",
"widget": {
"name": "string_a"
},
"link": 3
},
{
"name": "string_b",
"type": "STRING",
"widget": {
"name": "string_b"
},
"link": 4
}
],
"outputs": [
{
"name": "BOOLEAN",
"type": "BOOLEAN",
"links": [
5
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "StringCompare"
},
"widgets_values": [
"",
"",
"Starts With",
true
],
"color": "#232",
"bgcolor": "#353"
}
],
"links": [
[
3,
5,
0,
4,
0,
"STRING"
],
[
4,
6,
0,
4,
1,
"STRING"
],
[
5,
4,
0,
3,
0,
"BOOLEAN"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 1.2284597357367328,
"offset": [
-2371.487836752543,
-1201.4036934558803
]
},
"frontendVersion": "1.44.19"
},
"version": 0.4
}
It compares string_a and string_b, and outputs true if the condition matches, or false if it does not.
modeStarts With: whetherstring_astarts withstring_bEnds With: whetherstring_aends withstring_bEqual: whetherstring_aandstring_bare the same
- Set
case_sensitivetotrueto distinguish uppercase and lowercase.
MLLM
A slightly richer method is to use an MLLM to create a Boolean.
We said that a Boolean is represented as true / false, but it can also be represented as 1 / 0.
In other words, you can tell the MLLM, If it is XX, output 1; otherwise output 0, and then convert that result into a Boolean.

{
"id": "0bba12a8-d546-4b15-a099-13cb9870e6e3",
"revision": 0,
"last_node_id": 8,
"last_link_id": 10,
"nodes": [
{
"id": 1,
"type": "TextGenerate",
"pos": [
2903.298553740228,
1430.3770893064775
],
"size": [
400,
412
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [
{
"name": "clip",
"type": "CLIP",
"link": 1
},
{
"name": "image",
"shape": 7,
"type": "IMAGE",
"link": 5
},
{
"name": "video",
"shape": 7,
"type": "IMAGE",
"link": null
},
{
"name": "audio",
"shape": 7,
"type": "AUDIO",
"link": null
}
],
"outputs": [
{
"name": "generated_text",
"type": "STRING",
"links": [
4,
8
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "TextGenerate"
},
"widgets_values": [
"この画像に女性が映っていれば 1 を、そうでなければ 0 を出力してください。",
256,
"on",
0.7,
64,
0.95,
0.05,
1.05,
0,
0,
false,
true
],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 2,
"type": "CLIPLoader",
"pos": [
2579.1308760374027,
1430.3770893064775
],
"size": [
280.8288815898386,
106
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "CLIP",
"type": "CLIP",
"links": [
1
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "CLIPLoader"
},
"widgets_values": [
"qwen3.5_4b_bf16.safetensors",
"stable_diffusion",
"default"
],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 5,
"type": "ComfyNumberConvert",
"pos": [
3330.6504958704527,
1430.3770893064775
],
"size": [
178.0101231973421,
46
],
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"label": "value",
"name": "value",
"type": "INT,FLOAT,STRING,BOOLEAN",
"link": 4
}
],
"outputs": [
{
"name": "FLOAT",
"type": "FLOAT",
"links": null
},
{
"name": "INT",
"type": "INT",
"links": [
9
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "ComfyNumberConvert"
},
"widgets_values": [],
"color": "#432",
"bgcolor": "#653"
},
{
"id": 7,
"type": "ComfyMathExpression",
"pos": [
3536.0125611980197,
1430.3770893064775
],
"size": [
235.5094643140137,
143.8565237478972
],
"flags": {},
"order": 5,
"mode": 0,
"inputs": [
{
"label": "a",
"name": "values.a",
"type": "FLOAT,INT,BOOLEAN",
"link": 9
},
{
"label": "b",
"name": "values.b",
"shape": 7,
"type": "FLOAT,INT,BOOLEAN",
"link": null
}
],
"outputs": [
{
"name": "FLOAT",
"type": "FLOAT",
"links": null
},
{
"name": "INT",
"type": "INT",
"links": null
},
{
"name": "BOOL",
"type": "BOOLEAN",
"links": [
10
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "ComfyMathExpression"
},
"widgets_values": [
"a"
],
"color": "#432",
"bgcolor": "#653"
},
{
"id": 8,
"type": "PreviewAny",
"pos": [
3798.8739676422583,
1430.3770893064775
],
"size": [
210,
112
],
"flags": {},
"order": 6,
"mode": 0,
"inputs": [
{
"name": "source",
"type": "*",
"link": 10
}
],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PreviewAny"
},
"widgets_values": [
null,
null,
null
]
},
{
"id": 4,
"type": "PreviewAny",
"pos": [
3330.6504958704527,
1646.5910947583602
],
"size": [
210,
112
],
"flags": {},
"order": 4,
"mode": 0,
"inputs": [
{
"name": "source",
"type": "*",
"link": 8
}
],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PreviewAny"
},
"widgets_values": [
null,
null,
null
]
},
{
"id": 3,
"type": "LoadImage",
"pos": [
2579.1308760374027,
1605.568342010362
],
"size": [
280.8288815898386,
403.7872325736837
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
5
]
},
{
"name": "MASK",
"type": "MASK",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"0005_amodal_rebuild001_0005.png",
"image"
]
}
],
"links": [
[
1,
2,
0,
1,
0,
"CLIP"
],
[
4,
1,
0,
5,
0,
"STRING"
],
[
5,
3,
0,
1,
1,
"IMAGE"
],
[
8,
1,
0,
4,
0,
"STRING"
],
[
9,
5,
1,
7,
0,
"INT"
],
[
10,
7,
2,
8,
0,
"BOOLEAN"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 0.9229599817706495,
"offset": [
-2247.520386763948,
-1115.6613995536602
]
},
"frontendVersion": "1.44.19"
},
"version": 0.4
}
- Here, we use the
TextGeneratenode with Qwen 3.5 4B. - This is a little roundabout, but the MLLM output is text, meaning a
string, so we convert it to anint, and then convert that to aBoolean.
Compared with simple number or text comparisons, MLLMs can handle much more flexible and complex judgments.
- How many people are in this image?
- Which model fits this prompt better: anime or realistic?
- Is the output image quality good or bad?
Combining Multiple Conditions
Sometimes you want to combine multiple conditions, such as "the image height is 1000px or more and the width is less than 500px."
This is where logical operators are used.
AND / OR / NOT
There are three logical operators: AND / OR / NOT.
When there are multiple Boolean inputs, they output true or false based on the combination.

{
"id": "29b7b79f-f765-42d3-bf97-c0310f2e4ab1",
"revision": 0,
"last_node_id": 8,
"last_link_id": 8,
"nodes": [
{
"id": 1,
"type": "ComfyAndNode",
"pos": [
3243.655451593356,
1424.6992835911767
],
"size": [
180.474609375,
86
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [
{
"label": "value0",
"name": "values.value0",
"type": "*",
"link": 1
},
{
"label": "value1",
"name": "values.value1",
"shape": 7,
"type": "*",
"link": 2
},
{
"label": "value2",
"name": "values.value2",
"shape": 7,
"type": "*",
"link": null
}
],
"outputs": [
{
"name": "BOOLEAN",
"type": "BOOLEAN",
"links": [
6
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "ComfyAndNode"
},
"widgets_values": [],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 2,
"type": "ComfyOrNode",
"pos": [
3243.655451593356,
1600.9782195634316
],
"size": [
180.474609375,
86
],
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"label": "value0",
"name": "values.value0",
"type": "*",
"link": 3
},
{
"label": "value1",
"name": "values.value1",
"shape": 7,
"type": "*",
"link": 4
},
{
"label": "value2",
"name": "values.value2",
"shape": 7,
"type": "*",
"link": null
}
],
"outputs": [
{
"name": "BOOLEAN",
"type": "BOOLEAN",
"links": [
7
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "ComfyOrNode"
},
"widgets_values": [],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 3,
"type": "ComfyNotNode",
"pos": [
3243.655451593356,
1777.2571555356867
],
"size": [
180.474609375,
26
],
"flags": {},
"order": 4,
"mode": 0,
"inputs": [
{
"name": "value",
"type": "*",
"link": 5
}
],
"outputs": [
{
"name": "BOOLEAN",
"type": "BOOLEAN",
"links": [
8
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "ComfyNotNode"
},
"widgets_values": [],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 4,
"type": "PrimitiveBoolean",
"pos": [
2849.5866872595443,
1533.0468610425542
],
"size": [
270,
58
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "BOOLEAN",
"type": "BOOLEAN",
"links": [
1,
3
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PrimitiveBoolean"
},
"widgets_values": [
true
],
"color": "#2a363b",
"bgcolor": "#3f5159"
},
{
"id": 5,
"type": "PrimitiveBoolean",
"pos": [
2849.569497039055,
1656.9267808516133
],
"size": [
270,
58
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "BOOLEAN",
"type": "BOOLEAN",
"links": [
2,
4,
5
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PrimitiveBoolean"
},
"widgets_values": [
false
],
"color": "#322",
"bgcolor": "#533"
},
{
"id": 6,
"type": "PreviewAny",
"pos": [
3480.0359374991986,
1424.6992835911767
],
"size": [
241.08104976588402,
112
],
"flags": {},
"order": 5,
"mode": 0,
"inputs": [
{
"name": "source",
"type": "*",
"link": 6
}
],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PreviewAny"
},
"widgets_values": [
null,
null,
null
],
"color": "#322",
"bgcolor": "#533"
},
{
"id": 7,
"type": "PreviewAny",
"pos": [
3480.0359374991986,
1600.9782195634316
],
"size": [
241.08104976588402,
112
],
"flags": {},
"order": 6,
"mode": 0,
"inputs": [
{
"name": "source",
"type": "*",
"link": 7
}
],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PreviewAny"
},
"widgets_values": [
null,
null,
null
],
"color": "#2a363b",
"bgcolor": "#3f5159"
},
{
"id": 8,
"type": "PreviewAny",
"pos": [
3480.0359374991986,
1777.2571555356867
],
"size": [
241.08104976588402,
112
],
"flags": {},
"order": 7,
"mode": 0,
"inputs": [
{
"name": "source",
"type": "*",
"link": 8
}
],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PreviewAny"
},
"widgets_values": [
null,
null,
null
],
"color": "#2a363b",
"bgcolor": "#3f5159"
}
],
"links": [
[
1,
4,
0,
1,
0,
"BOOLEAN"
],
[
2,
5,
0,
1,
1,
"BOOLEAN"
],
[
3,
4,
0,
2,
0,
"BOOLEAN"
],
[
4,
5,
0,
2,
1,
"BOOLEAN"
],
[
5,
5,
0,
3,
0,
"BOOLEAN"
],
[
6,
1,
0,
6,
0,
"BOOLEAN"
],
[
7,
2,
0,
7,
0,
"BOOLEAN"
],
[
8,
3,
0,
8,
0,
"BOOLEAN"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 1.1167815779424861,
"offset": [
-2610.9052853223634,
-1235.8307818001963
]
},
"frontendVersion": "1.44.19"
},
"version": 0.4
}
- AND:
trueonly when all inputs aretrue - OR:
truewhen any input istrue - NOT: flips
trueandfalse
Of course, you can combine these.
For example, if you combine AND with NOT, you can output false when two inputs are both true.
No need to overthink it. Try using them and watch how they behave.
Practical Examples
Rotate 90 Degrees If the Image Is Portrait

{
"id": "b44355d7-ed6f-45da-8b10-a323c1253081",
"revision": 0,
"last_node_id": 11,
"last_link_id": 10,
"nodes": [
{
"id": 1,
"type": "LoadImage",
"pos": [
2804.885198733637,
1394.2279939324023
],
"size": [
279.21710715197923,
387.42527994692887
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
1,
7,
8
]
},
{
"name": "MASK",
"type": "MASK",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"0054_amodal_rebuild001_0055 (1).png",
"image"
]
},
{
"id": 3,
"type": "ComfyMathExpression",
"pos": [
3358.744771432823,
1611.8942365428447
],
"size": [
293.4438010526278,
158.81020881025938
],
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"label": "a",
"name": "values.a",
"type": "FLOAT,INT,BOOLEAN",
"link": 2
},
{
"label": "b",
"name": "values.b",
"shape": 7,
"type": "FLOAT,INT,BOOLEAN",
"link": 3
},
{
"label": "c",
"name": "values.c",
"shape": 7,
"type": "FLOAT,INT,BOOLEAN",
"link": null
}
],
"outputs": [
{
"name": "FLOAT",
"type": "FLOAT",
"links": null
},
{
"name": "INT",
"type": "INT",
"links": null
},
{
"name": "BOOL",
"type": "BOOLEAN",
"links": [
4
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "ComfyMathExpression"
},
"widgets_values": [
"a < b"
],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 4,
"type": "ComfySwitchNode",
"pos": [
3673.9612274799,
1394.2279939324023
],
"size": [
230.99505860380214,
78
],
"flags": {},
"order": 4,
"mode": 0,
"inputs": [
{
"name": "on_false",
"type": "IMAGE",
"link": 8
},
{
"name": "on_true",
"type": "IMAGE",
"link": 9
},
{
"name": "switch",
"type": "BOOLEAN",
"widget": {
"name": "switch"
},
"link": 4
}
],
"outputs": [
{
"name": "output",
"type": "IMAGE",
"links": [
10
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "ComfySwitchNode"
},
"widgets_values": [
false
],
"color": "#432",
"bgcolor": "#653"
},
{
"id": 11,
"type": "PreviewImage",
"pos": [
3936.81673188957,
1394.2279939324023
],
"size": [
367.53720929434166,
315.2072473810899
],
"flags": {},
"order": 5,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 10
}
],
"outputs": [],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PreviewImage"
},
"widgets_values": []
},
{
"id": 2,
"type": "GetImageSize",
"pos": [
3121.0626802023608,
1609.3754605618176
],
"size": [
210,
136
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [
{
"name": "image",
"type": "IMAGE",
"link": 1
}
],
"outputs": [
{
"name": "width",
"type": "INT",
"links": [
2
]
},
{
"name": "height",
"type": "INT",
"links": [
3
]
},
{
"name": "batch_size",
"type": "INT",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "GetImageSize"
},
"widgets_values": [],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 10,
"type": "ImageRotate",
"pos": [
3358.744771432823,
1480.0859384220487
],
"size": [
226.0425153311071,
58
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [
{
"name": "image",
"type": "IMAGE",
"link": 7
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
9
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "ImageRotate"
},
"widgets_values": [
"90 degrees"
],
"color": "#323",
"bgcolor": "#535"
}
],
"links": [
[
1,
1,
0,
2,
0,
"IMAGE"
],
[
2,
2,
0,
3,
0,
"INT"
],
[
3,
2,
1,
3,
1,
"INT"
],
[
4,
3,
2,
4,
2,
"BOOLEAN"
],
[
7,
1,
0,
10,
0,
"IMAGE"
],
[
8,
1,
0,
4,
0,
"IMAGE"
],
[
9,
10,
0,
4,
1,
"IMAGE"
],
[
10,
4,
0,
11,
0,
"IMAGE"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 0.7627768444385532,
"offset": [
-2311.7396288934533,
-909.3072739208028
]
},
"frontendVersion": "1.44.19"
},
"version": 0.4
}
- Get the image size with
Get Image Size - When the image is portrait,
width < heightbecomestrue - When it is
true, output the input image after rotating it withRotate Image
Change a Woman into a Man If a Woman Is Shown
If a woman is shown, change her into a man. Otherwise, remove all people.

{
"id": "e47d064a-cb92-4da7-b92b-be9f1ddd26f5",
"revision": 0,
"last_node_id": 70,
"last_link_id": 103,
"nodes": [
{
"id": 8,
"type": "VAEDecode",
"pos": [
1615.039087801503,
160.40068341159756
],
"size": [
161.111083984375,
46
],
"flags": {},
"order": 21,
"mode": 0,
"inputs": [
{
"name": "samples",
"type": "LATENT",
"link": 52
},
{
"name": "vae",
"type": "VAE",
"link": 62
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"slot_index": 0,
"links": [
65
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.39",
"Node name for S&R": "VAEDecode"
},
"widgets_values": []
},
{
"id": 43,
"type": "VAELoader",
"pos": [
517.231573621917,
656.7863480776692
],
"size": [
269.8313103058076,
58
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "VAE",
"type": "VAE",
"links": [
62,
76
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.39",
"Node name for S&R": "VAELoader"
},
"widgets_values": [
"flux2-vae.safetensors"
]
},
{
"id": 54,
"type": "ResizeImageMaskNode",
"pos": [
514.4495897676222,
484.74016932307575
],
"size": [
270,
106
],
"flags": {},
"order": 13,
"mode": 0,
"inputs": [
{
"name": "input",
"type": "IMAGE,MASK",
"link": 82
}
],
"outputs": [
{
"name": "resized",
"type": "IMAGE",
"links": [
80
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.9.2",
"Node name for S&R": "ResizeImageMaskNode"
},
"widgets_values": [
"scale to multiple",
16,
"nearest-exact"
]
},
{
"id": 52,
"type": "VAEEncode",
"pos": [
821.9650317382822,
484.74016932307575
],
"size": [
162,
46
],
"flags": {},
"order": 15,
"mode": 0,
"inputs": [
{
"name": "pixels",
"type": "IMAGE",
"link": 80
},
{
"name": "vae",
"type": "VAE",
"link": 76
}
],
"outputs": [
{
"name": "LATENT",
"type": "LATENT",
"links": [
74,
75
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.9.2",
"Node name for S&R": "VAEEncode"
},
"widgets_values": []
},
{
"id": 33,
"type": "CLIPTextEncode",
"pos": [
558.700000000001,
387.24938745307793
],
"size": [
425.2650317382812,
122.99611236572264
],
"flags": {
"collapsed": true
},
"order": 8,
"mode": 0,
"inputs": [
{
"name": "clip",
"type": "CLIP",
"link": 64
}
],
"outputs": [
{
"name": "CONDITIONING",
"type": "CONDITIONING",
"slot_index": 0,
"links": [
86
]
}
],
"title": "CLIP Text Encode (Negative Prompt)",
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.39",
"Node name for S&R": "CLIPTextEncode"
},
"widgets_values": [
""
]
},
{
"id": 57,
"type": "CLIPLoader",
"pos": [
-1046.5432691773194,
203.48293731896845
],
"size": [
280.8288815898386,
106
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "CLIP",
"type": "CLIP",
"links": [
87
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "CLIPLoader"
},
"widgets_values": [
"qwen3.5_4b_bf16.safetensors",
"stable_diffusion",
"default"
],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 58,
"type": "ComfyNumberConvert",
"pos": [
-295.0236493442684,
203.48293731896845
],
"size": [
178.0101231973421,
46
],
"flags": {},
"order": 12,
"mode": 0,
"inputs": [
{
"label": "value",
"name": "value",
"type": "INT,FLOAT,STRING,BOOLEAN",
"link": 89
}
],
"outputs": [
{
"name": "FLOAT",
"type": "FLOAT",
"links": null
},
{
"name": "INT",
"type": "INT",
"links": [
90
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "ComfyNumberConvert"
},
"widgets_values": [],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 6,
"type": "CLIPTextEncode",
"pos": [
558.700000000001,
160.40068341159756
],
"size": [
425.2650317382812,
167.9430462646484
],
"flags": {},
"order": 17,
"mode": 0,
"inputs": [
{
"name": "clip",
"type": "CLIP",
"link": 63
},
{
"name": "text",
"type": "STRING",
"widget": {
"name": "text"
},
"link": 96
}
],
"outputs": [
{
"name": "CONDITIONING",
"type": "CONDITIONING",
"slot_index": 0,
"links": [
70
]
}
],
"title": "CLIP Text Encode (Positive Prompt)",
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.39",
"Node name for S&R": "CLIPTextEncode"
},
"widgets_values": [
""
]
},
{
"id": 44,
"type": "CLIPLoader",
"pos": [
224.49879211425772,
292.66704483032197
],
"size": [
283.80000000000007,
106
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "CLIP",
"type": "CLIP",
"links": [
63,
64
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.73",
"Node name for S&R": "CLIPLoader"
},
"widgets_values": [
"qwen_3_8b.safetensors",
"flux2",
"default"
]
},
{
"id": 48,
"type": "UNETLoader",
"pos": [
917.2536154382312,
19.495025634765582
],
"size": [
308.1592787377913,
82
],
"flags": {},
"order": 3,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "MODEL",
"type": "MODEL",
"links": [
69
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.9.2",
"Node name for S&R": "UNETLoader"
},
"widgets_values": [
"Flux.2/flux-2-klein-9b-fp8.safetensors",
"default"
]
},
{
"id": 56,
"type": "TextGenerate",
"pos": [
-722.3755914744937,
203.48293731896845
],
"size": [
400,
412
],
"flags": {},
"order": 10,
"mode": 0,
"inputs": [
{
"name": "clip",
"type": "CLIP",
"link": 87
},
{
"name": "image",
"shape": 7,
"type": "IMAGE",
"link": 102
},
{
"name": "video",
"shape": 7,
"type": "IMAGE",
"link": null
},
{
"name": "audio",
"shape": 7,
"type": "AUDIO",
"link": null
}
],
"outputs": [
{
"name": "generated_text",
"type": "STRING",
"links": [
89
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "TextGenerate"
},
"widgets_values": [
"この画像に女性が映っていれば 1 を、そうでなければ 0 を出力してください。",
256,
"on",
0.7,
64,
0.95,
0.05,
1.05,
0,
0,
false,
true
],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 49,
"type": "ReferenceLatent",
"pos": [
1021.2781285510225,
160.40068341159756
],
"size": [
204.134765625,
46
],
"flags": {},
"order": 19,
"mode": 0,
"inputs": [
{
"name": "conditioning",
"type": "CONDITIONING",
"link": 70
},
{
"name": "latent",
"shape": 7,
"type": "LATENT",
"link": 75
}
],
"outputs": [
{
"name": "CONDITIONING",
"type": "CONDITIONING",
"links": [
71
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.9.2",
"Node name for S&R": "ReferenceLatent"
},
"widgets_values": []
},
{
"id": 59,
"type": "ComfyMathExpression",
"pos": [
-89.66158401670012,
203.48293731896845
],
"size": [
235.5094643140137,
143.8565237478972
],
"flags": {},
"order": 14,
"mode": 0,
"inputs": [
{
"label": "a",
"name": "values.a",
"type": "FLOAT,INT,BOOLEAN",
"link": 90
},
{
"label": "b",
"name": "values.b",
"shape": 7,
"type": "FLOAT,INT,BOOLEAN",
"link": null
}
],
"outputs": [
{
"name": "FLOAT",
"type": "FLOAT",
"links": null
},
{
"name": "INT",
"type": "INT",
"links": null
},
{
"name": "BOOL",
"type": "BOOLEAN",
"links": [
93
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "ComfyMathExpression"
},
"widgets_values": [
"a"
],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 64,
"type": "PrimitiveStringMultiline",
"pos": [
-252.1066255598296,
-220.87349522456816
],
"size": [
397.5504229008086,
144.88451526818943
],
"flags": {},
"order": 4,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": [
95
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PrimitiveStringMultiline"
},
"widgets_values": [
"Remove all people from the image."
],
"color": "#322",
"bgcolor": "#533"
},
{
"id": 65,
"type": "PrimitiveStringMultiline",
"pos": [
-248.07279349515574,
-20.209864694091635
],
"size": [
397.5504229008086,
144.88451526818943
],
"flags": {},
"order": 5,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": [
94
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PrimitiveStringMultiline"
},
"widgets_values": [
"Replace every woman in the image with a man, while keeping the same clothing, pose, position, hairstyle silhouette, lighting, camera angle, and scene composition."
],
"color": "#223",
"bgcolor": "#335"
},
{
"id": 63,
"type": "ComfySwitchNode",
"pos": [
220.08766704132302,
36.23429650683176
],
"size": [
270,
78
],
"flags": {},
"order": 16,
"mode": 0,
"inputs": [
{
"name": "on_false",
"type": "STRING",
"link": 95
},
{
"name": "on_true",
"type": "STRING",
"link": 94
},
{
"name": "switch",
"type": "BOOLEAN",
"widget": {
"name": "switch"
},
"link": 93
}
],
"outputs": [
{
"name": "output",
"type": "STRING",
"links": [
96,
98
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "ComfySwitchNode"
},
"widgets_values": [
false
],
"color": "#432",
"bgcolor": "#653"
},
{
"id": 67,
"type": "PreviewAny",
"pos": [
561.1172245661597,
-48.8577314253514
],
"size": [
320.47592717353996,
140.40191931344805
],
"flags": {},
"order": 18,
"mode": 0,
"inputs": [
{
"name": "source",
"type": "*",
"link": 98
}
],
"outputs": [
{
"name": "STRING",
"type": "STRING",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "PreviewAny"
},
"widgets_values": [
null,
null,
false
]
},
{
"id": 70,
"type": "CreateList",
"pos": [
-905.7143875874808,
484.74016932307575
],
"size": [
140,
66
],
"flags": {},
"order": 9,
"mode": 0,
"inputs": [
{
"label": "input0",
"name": "inputs.input0",
"type": "IMAGE",
"link": 100
},
{
"label": "input1",
"name": "inputs.input1",
"shape": 7,
"type": "IMAGE",
"link": 101
},
{
"label": "input2",
"name": "inputs.input2",
"shape": 7,
"type": "IMAGE",
"link": null
}
],
"outputs": [
{
"name": "list",
"shape": 6,
"type": "IMAGE",
"links": [
102,
103
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "CreateList"
}
},
{
"id": 51,
"type": "ResizeImageMaskNode",
"pos": [
209.97616959564456,
484.74016932307575
],
"size": [
270,
106
],
"flags": {},
"order": 11,
"mode": 0,
"inputs": [
{
"name": "input",
"type": "IMAGE,MASK",
"link": 103
}
],
"outputs": [
{
"name": "resized",
"type": "IMAGE",
"links": [
82
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.9.2",
"Node name for S&R": "ResizeImageMaskNode"
},
"widgets_values": [
"scale total pixels",
1,
"nearest-exact"
]
},
{
"id": 68,
"type": "LoadImage",
"pos": [
-1616.6685525637188,
486.1192079256388
],
"size": [
304.14064949086014,
536.4849883179598
],
"flags": {},
"order": 6,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
100
]
},
{
"name": "MASK",
"type": "MASK",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"000160_00004_.png",
"image"
]
},
{
"id": 62,
"type": "LoadImage",
"pos": [
-1266.6309825671176,
565.9597542315803
],
"size": [
304.14064949086014,
536.4849883179598
],
"flags": {},
"order": 7,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
101
]
},
{
"name": "MASK",
"type": "MASK",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.22.0",
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"000114_00005_.png",
"image"
]
},
{
"id": 31,
"type": "KSampler",
"pos": [
1262.7259909887628,
160.40068341159756
],
"size": [
315,
262
],
"flags": {},
"order": 20,
"mode": 0,
"inputs": [
{
"name": "model",
"type": "MODEL",
"link": 69
},
{
"name": "positive",
"type": "CONDITIONING",
"link": 71
},
{
"name": "negative",
"type": "CONDITIONING",
"link": 86
},
{
"name": "latent_image",
"type": "LATENT",
"link": 74
}
],
"outputs": [
{
"name": "LATENT",
"type": "LATENT",
"slot_index": 0,
"links": [
52
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.39",
"Node name for S&R": "KSampler"
},
"widgets_values": [
12345,
"fixed",
4,
1,
"euler",
"simple",
1
]
},
{
"id": 45,
"type": "SaveImage",
"pos": [
1813.4632685986182,
160.40068341159756
],
"size": [
684.1076792845461,
555.3306746679631
],
"flags": {},
"order": 22,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 65
}
],
"outputs": [],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.73"
},
"widgets_values": [
"ComfyUI"
]
}
],
"links": [
[
52,
31,
0,
8,
0,
"LATENT"
],
[
62,
43,
0,
8,
1,
"VAE"
],
[
63,
44,
0,
6,
0,
"CLIP"
],
[
64,
44,
0,
33,
0,
"CLIP"
],
[
65,
8,
0,
45,
0,
"IMAGE"
],
[
69,
48,
0,
31,
0,
"MODEL"
],
[
70,
6,
0,
49,
0,
"CONDITIONING"
],
[
71,
49,
0,
31,
1,
"CONDITIONING"
],
[
74,
52,
0,
31,
3,
"LATENT"
],
[
75,
52,
0,
49,
1,
"LATENT"
],
[
76,
43,
0,
52,
1,
"VAE"
],
[
80,
54,
0,
52,
0,
"IMAGE"
],
[
82,
51,
0,
54,
0,
"IMAGE"
],
[
86,
33,
0,
31,
2,
"CONDITIONING"
],
[
87,
57,
0,
56,
0,
"CLIP"
],
[
89,
56,
0,
58,
0,
"STRING"
],
[
90,
58,
1,
59,
0,
"INT"
],
[
93,
59,
2,
63,
2,
"BOOLEAN"
],
[
94,
65,
0,
63,
1,
"STRING"
],
[
95,
64,
0,
63,
0,
"STRING"
],
[
96,
63,
0,
6,
1,
"STRING"
],
[
98,
63,
0,
67,
0,
"STRING"
],
[
100,
68,
0,
70,
0,
"IMAGE"
],
[
101,
62,
0,
70,
1,
"IMAGE"
],
[
102,
70,
0,
56,
1,
"IMAGE"
],
[
103,
70,
0,
51,
0,
"IMAGE"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 0.4189769069935071,
"offset": [
1847.0845643468651,
533.2709120844096
]
},
"frontendVersion": "1.44.19",
"VHS_latentpreview": false,
"VHS_latentpreviewrate": 0,
"VHS_MetadataImage": true,
"VHS_KeepIntermediate": true
},
"version": 0.4
}
- Show the image to the MLLM, and make it output
1if a woman is shown, or0otherwise - When
true, switch to a prompt that changes the woman into a man; whenfalse, switch to a prompt that removes people - Pass the image and prompt to Flux.2 Klein 9B for image editing