Add type checking to queries