How-to: Conditional logic
Publicus has two conditional primitives:
- Switch routes execution down one of several branches. Cases are evaluated in order and the first matching case wins, like an if/else-if/else chain.
- ConditionalExit is a guard: if its condition is met the flow stops at that point; otherwise the flow continues.
Use Switch when different data should take different paths. Use ConditionalExit when the only alternative to continuing is stopping.
This guide covers the main patterns.
Branching with Switch
Section titled “Branching with Switch”Add a Switch node where the flow should split, then draw an edge from the Switch’s output to the first node of each branch.
Configure the Switch with an ordered list of cases. Each case has:
- a label that names the branch (shown in the run output, so make it descriptive),
- a condition expression that resolves truthy or falsy, using the same syntax as a ConditionalExit condition,
- a target node, the first node of the branch to take when this case is the first to match.
Cases are evaluated top to bottom. The first truthy condition wins and execution continues down that case’s branch only.
┌→ Mapper (purchase) → ...Webhook → Switch ───┼→ Mapper (refund) → ... └→ Mapper (other) → ... (default)case 1: label: purchase condition: $start->payload->type == "purchase"case 2: label: refund condition: $start->payload->type == "refund"default: the "other" branchConditions are bare boolean expressions, without {{ }} braces. In a
webhook flow the request body arrives under $start->payload, so the
event type is $start->payload->type.
The default branch
Section titled “The default branch”The default setting names the branch to take when no case matches,
acting as the else. Leave it empty and the run ends at the Switch
instead, which turns the Switch into a multi-way guard.
What happens to the other branches
Section titled “What happens to the other branches”Every branch that is not chosen is skipped: its nodes never run and produce no entries in the run report. If branches merge back into a shared node downstream, that shared node still runs.
The Switch itself outputs which branch it picked, including the matched case’s label, so the run report shows why the run went the way it did.


Branching on API errors
Section titled “Branching on API errors”HTTP nodes (REST and OpenAPI operations) can be configured to continue on upstream errors instead of failing the run. In that mode an error produces a structured output with the error message and upstream status code, which a downstream Switch can branch on:
case 1: label: upstream-error condition: $prev->error ?? falsedefault: the happy-path branchA successful response has no error field, so null-coalesce it to
false for the happy path.


This gives you a dedicated error-handling branch (alert, retry later, write to a store) without failing the whole flow.
Basic guard pattern
Section titled “Basic guard pattern”Place a ConditionalExit after any node to stop the flow when the
upstream output does not meet your criteria. The condition is the exit
predicate: write it as the reason to stop.
Webhook → ConditionalExit → ... rest of flow ...Configure the condition:
condition: $start->payload->type != "purchase"message: Not a purchase event — skipping.The flow stops for every event that is not a purchase; purchase events
fall through and continue.
Guard patterns by use case
Section titled “Guard patterns by use case”Each condition below is truthy exactly when the flow should stop.
Stop if a query returns no rows
Section titled “Stop if a query returns no rows”condition: count($prev) == 0message: No matching records found.$prev is the query’s result array. When no rows match, the array is
empty, so count($prev) == 0 is truthy and the flow stops.
Stop if a field is absent
Section titled “Stop if a field is absent”condition: ($prev->email ?? '') == ''message: Record has no email — skipping.Stop when an API response indicates no more data
Section titled “Stop when an API response indicates no more data”condition: !($prev->hasMore ?? false)message: All pages fetched — done.Deduplicate: stop if the record already exists
Section titled “Deduplicate: stop if the record already exists”-
Add a
TableStore / Queryto check for the record. -
Wire its output into a
ConditionalExit:condition: count($prev) > 0message: Record already exists — skipping insert.- The query found the record → the condition is truthy → the flow stops.
- The result array is empty → the condition is falsy → the flow continues to the insert.
That is the right logic for a deduplication guard.
Choosing between Switch and ConditionalExit
Section titled “Choosing between Switch and ConditionalExit”Reach for a Switch when there is more than one way forward. Reach for a ConditionalExit when the flow should either continue or stop, for example a dedupe check or a feature-flag gate. A ConditionalExit keeps the graph linear and records a message explaining why the run stopped; a Switch with an empty default can end a run too, but a guard says so more clearly.
The two combine well: guard early with ConditionalExit to filter out runs that should not happen at all, then Switch later to route the runs that remain.
Check a KV Store flag
Section titled “Check a KV Store flag”Use KeyValueStore / Get → ConditionalExit to gate a flow on a
runtime flag:
condition: $prev != "enabled"message: Feature flag disabled — skipping.KeyValueStore / Get outputs the stored value itself, so $prev
compares against it directly. You can also skip the Get node and read
the flag straight from the $kv root in the condition:
$kv->featureFlag != "enabled".
Change the KV entry value to "enabled" or "disabled" from the
Storage UI without touching the flow.
The message field
Section titled “The message field”The message is written to the run’s record when the condition is
truthy — that is, when the flow exits at the guard. Use it to explain
why the flow stopped so you can understand the run report without
re-reading the configuration:
message: Account {{ $start->accountId }} is not on the paid plan, skipping export.Expressions are resolved in the message field too.


Related
Section titled “Related”- Switch node reference.
- ConditionalExit node reference.
- Data mapping — expression syntax for conditions.
- Runs: view the exit message in the run timeline.