A pump shaft can be protected from chemical attack by using corrosion-resistant materials for the shaft, such as stainless steel or corrosion-resistant alloys. Additionally, applying protective coatings or linings on the shaft can provide an extra layer of defense against chemical attack. Regular maintenance, including cleaning and inspection, is also crucial to identify any signs of chemical attack and prevent further damage.