What’s the best way to let a user order items using boolean values and rules?

My application allows users to onboard their own applications by creating rules to dictate their configuration. These rules are created in a workflow and added to a table, so when they complete their process it will exist in a list like ["rule1', "rule2", "rule3", "rule4"]. We then want them to add a rule expression, to dictate how the configurations should be applied (i.e rule1 AND rule2 OR rule3 OR rule4 (always use rule1, use either rule2-4).

What the code does doesn't matter so much, it's how I want the user to enter this information. Right now I have just a text field for the user to write in rule1 AND rule2 OR rule3 OR rule4. I want it to be more intuitive though, and just having a textbox does not guide the user very well if they are new and not entirely sure what we are expecting. Also, We have to ensure the expression is in a proper format, so it would make validation easier if we can control what they enter. I've tried using dropdown boxes for this, but it didn't seem to be very visually appealing. Are there any other suggestions?