Added error detection to prompt