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 met must be connected
  • Not met not_met must be connected
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).

JSON
{ "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

SettingWhat it is for
fieldThe path of the value to test — into the input, the context or the output of an earlier node, such as context.plan. Required.
operatorHow the value is compared — eq, neq, gt, gte, lt, lte, contains, in or exists. Required.
valueWhat 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.

OperatorHolds when the value at the path…
equals, does not equalis, or is not, the value
greater than, greater or equal, less than, less or equalcompares so with the number
containsis text that contains the text of the value, or a list that has the value among its items
is one ofis one of the items of the list
existsis 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, null or 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. 5 and "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: 1 equals 1.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 equals null.

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

JSON
{ "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.

JSON
[
  { "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.

CheckMessage 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_numberThe value of “{node}” must be a number: its operator ({operator}) compares numbers.
condition_value_not_listThe 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.

Built from openapi b070e1f, sdk contract 5cc7055, php ae4a53b, node 84bc62d