Validate query before storing it