How to Write Custom Rules Safely