We propose a novel intent-based method to prevent security attacks on the safety functions in cyber-physical systems used in smart manufacturing. Context information about a cyber-physical system is collected from various sensors including non-safety sensors measuring device temperature, motor rotation speed, or instantaneous power consumption of machines. Such contextual information along with operational and business intent of the system under consideration are then used to check whether the current situation is indeed an emergency situation or a normal situation. Unlike the conventional safety systems that only rely on raw sensor data and safety protocol status packets from safety sensors, which might be spoofed and/or modified, decision on the safety situation in our method is intelligently made by comparing aggregated sensor information from the cyber-physical system and its environment for compliance with pre-configured operational intents that define the normal safe and secure operation of the system. We also show how to integrate Machine Learning (ML) and Artificial Intelligence (AI) into the proposed method for efficient and automated analysis of both intents and aggregated context information to make more intelligent decisions in execution of functional safety protocols. Our proposed AI/ML integration approach also enables the prediction of safety critical situations before they occur. The proposed method aims to prevent unnecessary switching to fail-safe mode causing insecure system states such as emergency doors opening or system halting in normal situations. In addition, it prevents sticking in non-safe states and not switching to fail-safe mode in real emergencies which could cause hazard on device and/or people.