Skip to main content

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 then routes the message to true_result or false_result depending on the evaluation.

The operator looks for single strings in the input (input_text) based on an operator and match text (match_text), but it can also search for multiple words by matching a regex. Available operators include:

  • equals: Exact match comparison
  • not equals: Inverse of exact match
  • contains: Checks if the match_text is found within input_text
  • starts with: Checks if input_text begins with match_text
  • ends with: Checks if input_text ends with match_text
  • regex: Matches on a case-sensitive pattern

By default, all operators are case insensitive except regex. regex is always case sensitive, and you can enable case sensitivity for all 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 with regex matching, and then output a different response depending on whether the match evaluated to true or false.

A conditional router connected to two OpenAI components

  1. Add an If-Else component to your flow, and then configure it as follows:

    • Text Input: Connect the Text Input port to a Chat Input component or another Message input.

      If your input isn't in Message format, you can use another component to transform it, such as the Type Convert component or Parser component. If your input isn't appropriate for Message format, consider using another component for conditional routing, such as the Data Operations component.

    • Match Text: Enter .*(urgent|warning|caution).* so the component looks for these values in incoming input. The regex match is case sensitive, so if you need to look for all permutations of warning, enter warning|Warning|WARNING.

    • Operator: Select regex.

    • Case True: In the component's header menu, click Controls, enable the Case True parameter, click Close, and then enter New Message Detected in the field.

      The Case True message is sent from the True output port when the match condition evaluates to true.

      No message is set for Case False so the component doesn't emit a message when the condition evaluates to false.

  2. Depending on what you want to happen when the outcome is True, add components to your flow to execute that logic:

    1. Add a Language Model, Prompt Template, and Chat Output component to your flow.

    2. In the Language Model component, enter your OpenAI API key or select a different provider and model.

    3. Connect the If-Else component's True output port to the Language Model component's Input port.

    4. 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.

    5. Connect the Prompt Template component to the Language Model component's System Message port.

    6. Connect the Language Model component's output to the Chat Output component.

  3. Repeat the same process with another set of Language Model, Prompt Template, and Chat Output components for the False outcome.

    Connect the If-Else component's False output port to the second Language Model component's Input port. 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 then send the flow some messages with and without your regex strings. The chat output should reflect the instructions in your prompts based on the regex evaluation.


    _10
    User: A new user was created.
    _10
    _10
    AI: A new low-priority message was received.
    _10
    _10
    User: Sign-in warning: new user locked out.
    _10
    _10
    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 parameters through the Controls in the component's header menu.

NameTypeDescription
input_textStringInput parameter. The primary text input for the operation.
match_textStringInput parameter. The text to compare against.
operatorDropdownInput parameter. The operator used to compare texts. Options include equals, not equals, contains, starts with, ends with, and regex. The default is equals.
case_sensitiveBooleanInput parameter. When true, the comparison is case sensitive. The default is false. This setting doesn't apply to regex comparisons.
max_iterationsIntegerInput parameter. The maximum number of iterations allowed for the conditional router. The default is 10.
default_routeDropdownInput parameter. The route to take when max iterations are reached. Options include true_result or false_result. The default is false_result.
true_resultMessageOutput parameter. The output produced when the condition is true.
false_resultMessageOutput parameter. The output produced when the condition is false.
Search