The vulnerability of artificial intelligence has emerged as a bottleneck, with adversarial attacks posing a significant threat to natural language processing. Although multiple defense mechanisms have been proposed, they often suffer from strict constraints, weak generalization, and low scalability. To address these challenges, we propose leveraging perplexity to quantify the difference between clean and adversarial examples based on the observation of numerous cases. We then statistically prove the substantial difference between them using Bayesian hypothesis testing. Subsequently, we develop an adversarial defense framework named UMPS, which contains two branches: “Uncovering the Mask”(UM) and “Perplexity-guided Sampling”(PS). UM utilizes a masked language model and Jaro-Winkler distance constraint to recover out-of-vocabulary words, while PS employs perplexity to locate the optimal sample within a convex hull which is constructed with integrated gradients. Theoretically, the proposed framework fulfills three requirements: effectiveness, universality, and portability. The experimental results demonstrate that UMPS effectively enhances the robustness of language models including BERT, against advanced attacks and outperforms three strong baseline methods. Furthermore, we conduct an instance analysis to illustrate how UMPS functions and what it outputs, an ablation study to support the validity and necessity of the two branches, and an post-hoc test on the difference in perplexity to explains the defense performance of our framework.