Condition
A node that compares one value of the execution with a value you set and sends the flow down one of two branches.
5 min read
Condition chooses a branch. It compares one value of the execution with a value you set, and leaves through Met or Not met.
- Node
- Condition
- Type
condition- Category
- Decision
- Ports
- Met
metmust be connected - Not met
not_metmust be connected
- Met
- Ends the path
- No
What it does
The node reads the value at the path of its field — in the input, the context or the output of an earlier node — and compares it with its value by its operator. When the comparison holds, the execution leaves through Met; otherwise through Not met. The node never fails the execution: when the path finds nothing the condition is not met, and neither is a comparison the operator cannot make — except under does not equal, which holds for a number against a number written as text (see Errors).
{ "field": "context.plan", "operator": "eq", "value": "pro" }When to use it
Give one kind of request another treatment: a plan, a region, a size of the input.
Refuse a request before the model is called: lead one branch to Reject Request.
Branch on what an earlier node left — the output of Transform, or the money outputs of the nodes before AI Model.
The node tests one comparison. For two, chain two nodes.
Settings
| Setting | What it is for |
|---|---|
field | The path of the value to test — into the input, the context or the output of an earlier node, such as context.plan. Required. |
operator | How the value is compared — eq, neq, gt, gte, lt, lte, contains, in or exists. Required. |
value | What the value is compared with. Its type is kept — a number, text, true, false, null, or a list for in. A number for gt, gte, lt and lte; none for exists. |
In the builder the settings are Field, Operator and Value. A new node tests input.plan.
| Operator | Holds when the value at the path… |
|---|---|
| equals, does not equal | is, or is not, the value |
| greater than, greater or equal, less than, less or equal | compares so with the number |
| contains | is text that contains the text of the value, or a list that has the value among its items |
| is one of | is one of the items of the list |
| exists | is there at all, null included. There is no value to set |
The value keeps its type. In the builder the value of equals and does not equal keeps its type when it reads as a number,
true,false,nullor JSON — a list, an object; anything else is text. Text that reads as one of them goes in quotes:"5". A list for is one of is typed with commas between its items, each read the same way. The four ordered operators take a number, and contains takes the text as typed, so in a list it finds a text item, never a number.A number is not equal to text.
5and"5"are not equal: equals is not met and does not equal is, and either way the trace says that the two sides were of different types. Two numbers are compared as numbers:1equals1.0.The four ordered operators need a number. The value at the path may be a number or a decimal string such as
"12.50", so an amount of money and a number the caller sent as text are compared as numbers.A string of the context is trimmed, and one left empty is
null: equals""on the context is never met, and does not equal""holds for any value that was sent. An empty value is tested with equalsnull.
Ports
The node has two ports, Met and Not met, and both are required. A flow in which either leads nowhere is not published.
Output
{ "met": true }A later node reads it as nodes.<key>.output.met.
Errors
The node raises no error. A path that finds nothing sends the execution through Not met whatever the operator, and the trace gets a warning event unknown_path. For the operator exists a missing value is the answer, and nothing is written.
Two values the operator cannot compare — such as a word where an ordered operator needs a number, a number where contains needs a text or a list, or a number against a number written as text — get a warning event type_mismatch. The answer is still the comparison's: such a pair is not met, so the execution leaves through Not met, except under does not equal: 5 is not equal to "5", and the execution leaves through Met.
[
{ "type": "warning", "node_key": "check", "payload": { "reason": "unknown_path", "field": "context.plan" } },
{ "type": "warning", "node_key": "check", "payload": { "reason": "type_mismatch", "field": "input.amount", "operator": "gt" } }
]The settings are checked when the flow is validated and when it is published.
In the API an entry of issues names such a check in params.detail; its code is invalid_node_config.
| Check | Message in the builder |
|---|---|
condition_needs_field | “{node}” needs a field to test. |
condition_field_bad_path | “{node}” tests “{path}”, which is not a path into input, context or nodes. |
condition_field_unknown_node | “{node}” tests “{path}”, but the flow has no node “{ref}”. |
condition_field_later_node | “{node}” tests “{path}”, but “{ref}” does not run before it — its output does not exist yet there. |
condition_unsupported_operator | “{node}” uses an operator that does not exist. |
condition_needs_value | “{node}” needs a value to compare against. |
condition_value_not_number | The value of “{node}” must be a number: its operator ({operator}) compares numbers. |
condition_value_not_list | The value of “{node}” must be a non-empty list: its operator checks that the field is one of the listed values. |
Example
- Request — Default → Condition
- Condition — Met → AI Model
- Condition — Not met → Reject Request
- AI Model — Success → Return Response
The node tests context.plan equals "pro". A request of the plan is answered by the model; any other one is refused by Reject Request with the code its author set.
Related
Execution context and paths — what a path may read, and what each node leaves.
Ports and branching — required ports and where a port leads.
Send a request — what the context of a call holds.
Built from openapi b070e1f, sdk contract 5cc7055, php ae4a53b, node 84bc62d