query_check function

Check whether the user-provided query is valid