To address the issue of uncertainty in the occurrence time of voltage sags in power grids, which affects power quality, a voltage state prediction method based on LSTM neural networks is proposed for predicting voltage states. For the problem of quickly and accurately compensating for voltage sags, a DVR system based on a new approach law of sliding mode variable structure control is proposed, which significantly reduces chattering, improves response speed, and enhances the robustness of the system. The stability of the system is proven based on Lyapunov stability theory. Simulation experiments are conducted to analyze the voltage state prediction effect based on the LSTM neural network and the compensation effect of the novel reaching law of sliding mode variable structure control under different levels of voltage sag, validating the effectiveness and correctness of the proposed solution.