{"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/improved-few-shot-jailbreaking-can-circumvent","title":"Improved Few-Shot Jailbreaking Can Circumvent Aligned Language Models and Their Defenses","arxiv_id":"2406.01288","date":"2024-06-03","proceeding":null,"authors":["Xiaosen Zheng","Tianyu Pang","Chao Du","Qian Liu","Jing Jiang","Min Lin"],"abstract":"Recently, Anil et al. (2024) show that many-shot (up to hundreds of) demonstrations can jailbreak state-of-the-art LLMs by exploiting their long-context capability. Nevertheless, is it possible to use few-shot demonstrations to efficiently jailbreak LLMs within limited context sizes? While the vanilla few-shot jailbreaking may be inefficient, we propose improved techniques such as injecting special system tokens like [/INST] and employing demo-level random search from a collected demo pool. These simple techniques result in surprisingly effective jailbreaking against aligned LLMs (even with advanced defenses). For examples, our method achieves >80% (mostly >95%) ASRs on Llama-2-7B and Llama-3-8B without multiple restarts, even if the models are enhanced by strong defenses such as perplexity detection and/or SmoothLLM, which is challenging for suffix-based jailbreaking. In addition, we conduct comprehensive and elaborate (e.g., making sure to use correct system prompts) evaluations against other aligned LLMs and advanced defenses, where our method consistently achieves nearly 100% ASRs. Our code is available at https://github.com/sail-sg/I-FSJ.","url_abs":"https://arxiv.org/abs/2406.01288v2","url_pdf":"https://arxiv.org/pdf/2406.01288v2.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":"improved-few-shot-jailbreaking-can-circumvent","repo_url":"https://github.com/sail-sg/i-fsj","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[],"methods":[{"method_slug":"random-search","method_name":"Random Search"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2406.01288","atlas_url":"https://app.syntology.ai/?focus=2406.01288","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2406.01288"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-25T09:33:49+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/sail-sg/I-FSJ","reach":{"status":"ok","spdx":"MIT"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/sail-sg/i-fsj","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"ran":2,"unverified":9},"by_repo_kind":{"official":{"samples":11,"ran":2,"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":0,"samples":[{"code_sha256_prefix":"a2058f7fc99001a7","entry":"check_for_attack_success","repo":"sail-sg/I-FSJ","repo_kind":"official","path":"exps/rs.py","file_url":"https://github.com/sail-sg/I-FSJ/blob/HEAD/exps/rs.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a2058f7fc99001a7"}},{"code_sha256_prefix":"3a80a2bfa48e30bb","entry":"generate","repo":"sail-sg/I-FSJ","repo_kind":"official","path":"exps/rs.py","file_url":"https://github.com/sail-sg/I-FSJ/blob/HEAD/exps/rs.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"3a80a2bfa48e30bb"}},{"code_sha256_prefix":"71b177b3a3ed6078","entry":"combine_prompts","repo":"sail-sg/I-FSJ","repo_kind":"official","path":"api_experiments/evaluate_api_models.py","file_url":"https://github.com/sail-sg/I-FSJ/blob/HEAD/api_experiments/evaluate_api_models.py","link_basis":"plan_row","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"71b177b3a3ed6078"}},{"code_sha256_prefix":"0bf2136a7171ae80","entry":"get_embedding_layer","repo":"sail-sg/I-FSJ","repo_kind":"official","path":"llm_attacks/base/attack_manager.py","file_url":"https://github.com/sail-sg/I-FSJ/blob/HEAD/llm_attacks/base/attack_manager.py","link_basis":"plan_row","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"0bf2136a7171ae80"}},{"code_sha256_prefix":"688aaeba506e3329","entry":"get_embedding_matrix","repo":"sail-sg/I-FSJ","repo_kind":"official","path":"llm_attacks/base/attack_manager.py","file_url":"https://github.com/sail-sg/I-FSJ/blob/HEAD/llm_attacks/base/attack_manager.py","link_basis":"plan_row","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"688aaeba506e3329"}},{"code_sha256_prefix":"f556dda0785f3c77","entry":"get_embeddings","repo":"sail-sg/I-FSJ","repo_kind":"official","path":"llm_attacks/base/attack_manager.py","file_url":"https://github.com/sail-sg/I-FSJ/blob/HEAD/llm_attacks/base/attack_manager.py","link_basis":"plan_row","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"f556dda0785f3c77"}},{"code_sha256_prefix":"25ae440509f39ec5","entry":"get_filtered_cands","repo":"sail-sg/I-FSJ","repo_kind":"official","path":"llm_attacks/minimal_gcg/opt_utils.py","file_url":"https://github.com/sail-sg/I-FSJ/blob/HEAD/llm_attacks/minimal_gcg/opt_utils.py","link_basis":"plan_row","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"25ae440509f39ec5"}},{"code_sha256_prefix":"645890ba00019a69","entry":"load_prompts","repo":"sail-sg/I-FSJ","repo_kind":"official","path":"api_experiments/evaluate_api_models.py","file_url":"https://github.com/sail-sg/I-FSJ/blob/HEAD/api_experiments/evaluate_api_models.py","link_basis":"plan_row","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"645890ba00019a69"}},{"code_sha256_prefix":"d0e94f216f27f804","entry":"make_checking_fn","repo":"sail-sg/I-FSJ","repo_kind":"official","path":"api_experiments/evaluate_api_models.py","file_url":"https://github.com/sail-sg/I-FSJ/blob/HEAD/api_experiments/evaluate_api_models.py","link_basis":"plan_row","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"d0e94f216f27f804"}},{"code_sha256_prefix":"1e8c1c46e0ec7dad","entry":"sample_control","repo":"sail-sg/I-FSJ","repo_kind":"official","path":"exps/rs.py","file_url":"https://github.com/sail-sg/I-FSJ/blob/HEAD/exps/rs.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"1e8c1c46e0ec7dad"}},{"code_sha256_prefix":"94d7ddaf0169dbf1","entry":"sample_control","repo":"sail-sg/I-FSJ","repo_kind":"official","path":"llm_attacks/minimal_gcg/opt_utils.py","file_url":"https://github.com/sail-sg/I-FSJ/blob/HEAD/llm_attacks/minimal_gcg/opt_utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"94d7ddaf0169dbf1"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}