If-Else
The If-Else component is a conditional router that routes messages by comparing two strings. It evaluates a condition by comparing two text inputs using the specified operator and routes the message to true_result or false_result based on the evaluation.
The operator checks for strings in the input (input_text) based on the selected operator and match text (match_text). It can also search for multiple words using a regular expression. Available operators include:
a. equals: Exact match comparison.
b. not equals: Inverse of exact match.
c. contains: Checks if match_text is found within input_text.
d. starts with: Checks if input_text begins with match_text.
e. ends with: Checks if input_text ends with match_text.
f. regex: Matches a case-sensitive pattern.
By default, all operators are case insensitive except regex. The regex operator is always case sensitive. You can enable case sensitivity for the other operators in the If-Else parameters.
Use the If-Else component in a flow
The following example uses the If-Else component to check incoming chat messages using regex matching and output a different response depending on whether the condition evaluates to true or false.
1. Add an If-Else component to your flow and configure it as follows:
a. Text Input: Connect the Text Input port to a Chat Input component or another Message input.
b. Match Text: Enter .*(urgent|warning|caution).* so the component looks for these values in the incoming input. The regex match is case sensitive. To match different case variations, specify them in the expression, such as warning|Warning|WARNING.
c. Operator: Select regex.
d. Case True: Enable the Case True parameter and enter New Message Detected.
The Case True message is sent through the True output port when the match condition evaluates to true.
Leave Case False blank. When the condition evaluates to false, the component routes the original Text Input to the False output port.
2. Depending on what you want to happen when the outcome is True, add components to your flow to execute that logic:
a. Add a Robility Model, Prompt Template, and Chat Output component to your flow.
b. Configure the Robility Model component with the required model provider and model.
c. Connect the If-Else component’s True output port to the Robility Model component’s input.
d. In the Prompt Template component, enter instructions for the model when the evaluation is true, such as Send a message that a new warning, caution, or urgent message was received.
e. Connect the Prompt Template component to the Robility Model component’s System Message port.
f. Connect the Robility Model component’s output to the Chat Output component.
3. Repeat the same process with another set of Robility Model, Prompt Template, and Chat Output components for the False outcome.
Connect the If-Else component’s False output port to the second Robility Model component’s input. In the second Prompt Template, enter instructions for the model when the evaluation is false, such as Send a message that a new low-priority message was received.
4. To test the flow, open the Playground and send messages with and without the specified regex strings. The chat output should reflect the instructions in your prompts based on the regex evaluation.
User: A new user was created.
AI: A new low-priority message was received.
User: Sign-in warning: new user locked out.
AI: A new warning, caution, or urgent message was received. Please review it at your earliest convenience.If-Else parameters
Some parameters are hidden by default in the visual editor. You can modify all component parameters through the component inspection panel when you select the component.
| Parameter | Type | Description |
|---|---|---|
| Text Input | Input | The input text to be evaluated by the If-Else component. |
| Operator | Input |
Specifies the comparison operation to perform on the Text Input and Match Text. Options include equals, not equals, contains, starts with, ends with, and regex.
|
| Match Text | Input | The text or pattern to compare against the Text Input based on the selected operator. |
| Case Sensitive | Input | Determines whether the text comparison considers letter casing. When enabled, the comparison is case sensitive. |
| Case True | Input | Specifies the message to be returned through the True output when the condition evaluates to true. |
| Case False | Input | Specifies the message to be returned through the False output when the condition evaluates to false. |
| Max Iterations | Input |
Specifies the maximum number of iterations allowed for conditional routing. The default value is 10.
|
| Default Route | Input |
Specifies the output route to use when the maximum number of iterations is reached. Options include true_result and false_result. The default is false_result.
|
| True | Output | Returns the result when the condition evaluates to true. |
| False | Output | Returns the result when the condition evaluates to false. |