Encapsulate query validation logic