{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/cold-attack-jailbreaking-llms-with","title":"COLD-Attack: Jailbreaking LLMs with Stealthiness and Controllability","arxiv_id":"2402.08679","date":"2024-02-13","proceeding":null,"authors":["Xingang Guo","Fangxu Yu","huan zhang","Lianhui Qin","Bin Hu"],"abstract":"Jailbreaks on large language models (LLMs) have recently received increasing attention. For a comprehensive assessment of LLM safety, it is essential to consider jailbreaks with diverse attributes, such as contextual coherence and sentiment/stylistic variations, and hence it is beneficial to study controllable jailbreaking, i.e. how to enforce control on LLM attacks. In this paper, we formally formulate the controllable attack generation problem, and build a novel connection between this problem and controllable text generation, a well-explored topic of natural language processing. Based on this connection, we adapt the Energy-based Constrained Decoding with Langevin Dynamics (COLD), a state-of-the-art, highly efficient algorithm in controllable text generation, and introduce the COLD-Attack framework which unifies and automates the search of adversarial LLM attacks under a variety of control requirements such as fluency, stealthiness, sentiment, and left-right-coherence. The controllability enabled by COLD-Attack leads to diverse new jailbreak scenarios which not only cover the standard setting of generating fluent (suffix) attack with continuation constraint, but also allow us to address new controllable attack settings such as revising a user query adversarially with paraphrasing constraint, and inserting stealthy attacks in context with position constraint. Our extensive experiments on various LLMs (Llama-2, Mistral, Vicuna, Guanaco, GPT-3.5, and GPT-4) show COLD-Attack's broad applicability, strong controllability, high success rate, and attack transferability. Our code is available at https://github.com/Yu-Fangxu/COLD-Attack.","url_abs":"https://arxiv.org/abs/2402.08679v2","url_pdf":"https://arxiv.org/pdf/2402.08679v2.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"cold-attack-jailbreaking-llms-with","repo_url":"https://github.com/yu-fangxu/cold-attack","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok"}}],"tasks":[{"task_slug":"text-generation","task_name":"Text Generation"}],"methods":[{"method_slug":"adam","method_name":"Adam"},{"method_slug":"attention","method_name":"Attention"},{"method_slug":"attention-dropout","method_name":"Attention Dropout"},{"method_slug":"bpe","method_name":"BPE"},{"method_slug":"cosine-annealing","method_name":"Cosine Annealing"},{"method_slug":"dense-connections","method_name":"Dense Connections"},{"method_slug":"dropout","method_name":"Dropout"},{"method_slug":"gpt-3","method_name":"GPT-3"},{"method_slug":"layer-normalization","method_name":"Layer Normalization"},{"method_slug":"linear-layer","method_name":"Linear Layer"},{"method_slug":"linear-warmup-with-cosine-annealing","method_name":"Linear Warmup With Cosine Annealing"},{"method_slug":"multi-head-attention","method_name":"Multi-Head Attention"},{"method_slug":"residual-connection","method_name":"Residual Connection"},{"method_slug":"softmax","method_name":"Softmax"},{"method_slug":"weight-decay","method_name":"Weight Decay"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2402.08679","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2402.08679"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"deterministic:regex_extraction","url":"https://github.com/Yu-Fangxu/COLD-Attack","reach":{"status":"ok"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/yu-fangxu/cold-attack","reach":{"status":"ok"}}],"summary":{"ran":7,"unverified":4},"by_repo_kind":{"official":{"samples":11,"ran":7,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":11,"samples":[{"code_sha256_prefix":"d4931205d88652cd","entry":"batch_log_bleulosscnn_ae","repo":"Yu-Fangxu/COLD-Attack","repo_kind":"official","path":"bleuloss.py","file_url":"https://github.com/Yu-Fangxu/COLD-Attack/blob/HEAD/bleuloss.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"d4931205d88652cd"}},{"code_sha256_prefix":"3750fb31740c296d","entry":"embed_inputs","repo":"Yu-Fangxu/COLD-Attack","repo_kind":"official","path":"util.py","file_url":"https://github.com/Yu-Fangxu/COLD-Attack/blob/HEAD/util.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"3750fb31740c296d"}},{"code_sha256_prefix":"886d1670186fba06","entry":"load_model_and_tokenizer","repo":"Yu-Fangxu/COLD-Attack","repo_kind":"official","path":"opt_util.py","file_url":"https://github.com/Yu-Fangxu/COLD-Attack/blob/HEAD/opt_util.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"886d1670186fba06"}},{"code_sha256_prefix":"84c0bec2c35fbb5b","entry":"post_process","repo":"Yu-Fangxu/COLD-Attack","repo_kind":"official","path":"evaluate.py","file_url":"https://github.com/Yu-Fangxu/COLD-Attack/blob/HEAD/evaluate.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"84c0bec2c35fbb5b"}},{"code_sha256_prefix":"57e9e15822383309","entry":"remove_special_characters","repo":"Yu-Fangxu/COLD-Attack","repo_kind":"official","path":"evaluate.py","file_url":"https://github.com/Yu-Fangxu/COLD-Attack/blob/HEAD/evaluate.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"57e9e15822383309"}},{"code_sha256_prefix":"e881ba8900d535da","entry":"remove_special_characters","repo":"Yu-Fangxu/COLD-Attack","repo_kind":"official","path":"evaluate.py","file_url":"https://github.com/Yu-Fangxu/COLD-Attack/blob/HEAD/evaluate.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"e881ba8900d535da"}},{"code_sha256_prefix":"e808c2cfad1bde78","entry":"top_k_filter_3d","repo":"Yu-Fangxu/COLD-Attack","repo_kind":"official","path":"util.py","file_url":"https://github.com/Yu-Fangxu/COLD-Attack/blob/HEAD/util.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"e808c2cfad1bde78"}},{"code_sha256_prefix":"0db91cccc1a0e494","entry":"embed_inputs_target","repo":"Yu-Fangxu/COLD-Attack","repo_kind":"official","path":"util.py","file_url":"https://github.com/Yu-Fangxu/COLD-Attack/blob/HEAD/util.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"0db91cccc1a0e494"}},{"code_sha256_prefix":"dac727bfcfa835e4","entry":"main","repo":"yu-fangxu/cold-attack","repo_kind":"official","path":"cold_decoding.py","file_url":"https://github.com/yu-fangxu/cold-attack/blob/HEAD/cold_decoding.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"dac727bfcfa835e4"}},{"code_sha256_prefix":"abfc8db992071842","entry":"options","repo":"yu-fangxu/cold-attack","repo_kind":"official","path":"cold_decoding.py","file_url":"https://github.com/yu-fangxu/cold-attack/blob/HEAD/cold_decoding.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"abfc8db992071842"}},{"code_sha256_prefix":"9bb79ab60469224a","entry":"seed_everything","repo":"yu-fangxu/cold-attack","repo_kind":"official","path":"cold_decoding.py","file_url":"https://github.com/yu-fangxu/cold-attack/blob/HEAD/cold_decoding.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"9bb79ab60469224a"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}