You can return the layer list instead of converting to a string and then adapt your syntax a little by using the `array_contains` function on the output in the expression. ```python @qgsfunction(args='auto', group='Custom') def my_filter(layer_group, feature, parent): root = QgsProject.instance().layerTreeRoot() my_group = root.findGroup(layer_group) layer_list = [layer.name() for layer in my_group.children() if layer.isVisible()] # return the list of layers return layer_list ``` Expression ```expression array_contains(my_filter('my group'), "FIELD_1") ``` [![enter image description here][1]][1] I used *Select by Expression* to demonstrate the result, rather than rule-based symbology, but the principle remains the same. [1]: https://i.sstatic.net/WiiHKiEw.png