/

Building Apps

/

Conditions can be applied to functions in your workflow logic to dictate if a certain function should be executed.

To understand how conditions work in Moonlit we will take this simple app as an example where have 2 functions, a scrape webpage and a chat model. The goal for this app is to analyse a given page contents.

In the inputs we have a single text input labelled as Page Copy or URL the goal here is to use conditions to scrape the page if the user provided a URL, otherwise the user provided the copy itself and that will be passed directly to the chat model.

To apply the condition, click on the small plus button right under the node ID.

Here we have two fields for setting up the condition, first the condition itself.

You can write conditions and reference variables here using the syntax:  
[condition] [operation] [value]  
  
This can also be followed by logic gates (and, or) with the syntax:  
  
[condition1] [operation1] [value1] [logic gate] [condition2] [operation2] [value2]

You can hover over the Learn about condition syntax link to view available operations, logic gates, and examples.

In this example, we want to check if the 'Copy or URL' input is a URL, so we will use the following expression:

"{{Copy or URL}}" startswith "https://"

For the second field we have a 'Fallback Value' this is the value to be returned if the expression evaluates to false. So this will be simply the input itself containing the page copy.

That's it, now in the test tab of your app. if you provide a url the scrape function will run and fetch the page contents to pass them to the Chat Model, otherwise if you for example still haven't published your draft you can paste in the draft and that would be directly passed to the Chat Model.