Integrating Rules
Rulebricks Flows

Rule Flows

Rule Flows

Rule Flows are a powerful way to chain together multiple rules, alongside calls to external services, and create complex decision-making workflows.

Rule Flows are particularly useful when you have a series of decisions that need to be made in a specific order, or when you'd like to separate logic into multiple rules for easier maintenance of your decision-making logic.

Creating a Rule Flow

Navigate to the Flows tab

Open the Rulebricks dashboard, and click the "Flows" tab.

Flows Tab

Create a new flow

Click the "Create Flow" button to create a new Rule Flow. Note that in order to create a Rule Flow, you must have at least one rule created and published in your workspace to use as a starting point for your flow.

Create Flow

Upon creating a new flow, you'll be taken to the Rule Flow editor, where you can drag and drop other published rules in your workspace from the sidebar onto the canvas, and connect them together to create a flow.

There are a few other nodes you can add to your flow as well, such as the code execution node, which allows you to make calls to external services, amongst other things, and an important Result Object node, which is the final output of your flow.

Rule Flow Editor

Connect your nodes

Try adding a few rules to your flow, and connecting them together. You can drag and drop the nodes around the canvas, and connect them together by dragging from an output handle of one node to the input of another.

Rule Flow Editor


Flow Reactivity

The Rulebricks Flow editor is "reactive", meaning that as you make changes to rule input fields in your flow, the editor will automatically update the results of your flow in real-time. This makes it easy to see how your flow behaves as you build it out.

Reactivity applies to all sequences of nodes until code execution nodes are reached, at which point the flow will pause and wait for you to manually run the code execution node using the button on it before continuing. This is to ensure any external services you're calling are only called when you're ready and are not spammed with requests.


Flow Functions

There are several "Flow Functions" available in Rulebricks, which are special operations that can be used in your Rule Flows to perform various actions that may prove valuable integrating Rulebricks into your existing processes.

Flow Functions

We'll cover each of these functions in more detail below.

For Each

For Each

The For Each node allows you to iterate over a list of items and apply a rule to each item in the list. This is useful when you have a list of items and you want to apply a rule to each item in the list.

If your list contains objects/values, For Each nodes will automatically explode the object into individual fields that can you can use in your flow. If your list is empty, the For Each node will not know what values to iterate over and will remain empty and unusable.

For Each nodes must culminate in a Result Object node, which will collect the results of each iteration and be used to return a transformed list of items.

Note that because values in the For Each node are being iterated over and within a specific loop, they cannot connect to parts of your flow that are not within or downstream of that same loop. This is intentional and indicated by a change in the color of connecting edges emitted from the For Each node.

If/Else

If/Else

The If/Else node allows you to proceed based on if a condition is true or "truthy" (not empty, non-zero, non-null). If the condition is true, the flow will continue along the edges from the "True" section, otherwise, it will continue along the edges from the "False" section. This flow function is useful if you would like to only execute specific parts of your flow.

Result Object

The Result Object node is the final output of your flow. It collects the results of all the nodes that precede it in the flow and returns the final output of your flow. You may use multiple Result Object nodes in your flow, as long as they contain unique keys in which to store the results.

Lookup Table

Lookup Table

The Lookup Table node allows you to look up a value in a table and return a corresponding value if an exact match is found. Lookup Tables can work well with If/Else nodes by returning true or false based on the lookup result.

Run Code

The Run Code node allows you to run custom Javascript code in your flow, using data from inside your flow. This is useful if you need to make calls to external services, perform complex calculations, or perform other custom operations that are not supported by the other flow functions. For ease of use, certain libraries, like fetch and moment are made available for you to use in your code.

You can access values from connected nodes in the Run Code node by using the inputs dictionary, and you modify/return values from the Run Code node by updating values in this same dictionary. Global values and variables outside of the inputs dictionary will not be returned.

Database Query

DB Query

The Database Query node allows you to query a PostgreSQL database table and return the results. This is useful if you need to retrieve data from a database table and use it in your flow, or if you need to update data in a database table based on the results of your flow. Variables from your flow can be used in the query, and the results of the query can be used in subsequent nodes in your flow.

API Request

The API Request node allows you to make an HTTP request to an external API and return the results. This is useful if you need to retrieve data from an external API and use it in your flow, or if you need to update data in an external API based on the results of your flow. Variables from your flow can be used in the request URL, headers, and body, and the results of the request can be used in subsequent nodes in your flow.

AI Inference

AI Inference

The AI Inference node allows you extract structured data to execute rules on from text using OpenAI's latest model. This is extremely useful if you'd like to extract specific information from things like emails and reports, and use that information in your flow, all natively within Rulebricks.

To use the AI Inference node, just connect a text input into the node on the left, define the structured data you'd like to extract in the node UI by clicking "+ Add Target Label", and click "Run Inference".