JEDI: Real-Time Jailbreak Defense for LLMs via In-Generation Detection and Intervention
Abstract
Large Language Models remain vulnerable to jailbreak attacks, and streaming generation can expose harmful prefixes before a completed response is moderated. We present JEDI, an in-generation defense that monitors hidden-state risk and selectively steers ongoing generation. A Condition Vector measures harmful-compliance drift, a Cumulative Sum (CUSUM) statistic accumulates persistent evidence, and a separate, orthogonalized Intervention Vector applies risk-adaptive refusal steering after an alarm. Across six publicly available models and eleven attack methods, JEDI achieves 95.7\% mean Defense Success Rate, with model-level rates of 93.6%-99.4%, and adds 0.003 seconds to average Time To First Token. Comparisons with periodic buffered guards, conditional activation steering, and trajectory monitoring characterize the safety-utility-latency trade-off. A matched visible-prefix audit reports both raw detector-positive onsets and evaluator-consensus leakage, showing substantial reductions while identifying residual exposure. Controlled component ablations support distinct roles for accumulated risk, orthogonalization, and dynamic intervention. JEDI targets self-hosted or model-developer deployments with hidden-state access and decoding control. Code and experimental results are available at https://github.com/samxrl/JEDI.