virtual-prompt-injection
Unofficial implementation of Virtual Prompt Injection attack on instruction-tuned LLMs
GraphCanon updated 2w · GitHub synced 2w
Decision brief
Virtual Prompt Injection provides an unofficial implementation for backdooring instruction-tuned LLMs with virtual prompt injection, offering tools for data poisoning and evaluation specific to this technique.
Good fit when
- If needing to simulate or study backdoor attacks specifically targeting the behavior of trained language models under certain scenarios without modifying input directly at inference time.
- For researchers aiming to evaluate the robustness of LLMs against sophisticated, hidden prompts that can alter model outputs in specific contexts.
Avoid when
- Not applicable for general training or serving tasks if backdoor insertion is not within scope as it focuses solely on simulating attacks.
- In a production environment where tampering with AI models' integrity and security is strictly prohibited due to ethical considerations.
Observed Jul 12, 2026 · Source: enrich:decision_facts
Verify the decision
Maintenance and security
Full trust report- Maintenance
- Dormant (759d since push)
- As of 2w
- Provenance
- Not a fork · Personal account
- As of 2w
- Security (OSV)
- No lockfile
- As of 1mo
Public GitHub metadata and optional OSV scans. Signals, not a guarantee. Trust methodology.
Install
pip install virtual-prompt-injection PyPISimilar tools
Same-category neighbours. No typed graph edges are catalogued for this tool yet.
Evidence and technical details
Sourced facts, taxonomy, compatibility claims, README excerpt, and machine-readable endpoints.
Overview
This repository contains an unofficial implementation of the paper 'Backdooring Instruction-Tuned Large Language Models with Virtual Prompt Injection', focusing on data poisoning and evaluation for virtual prompt injection, as well as Alpaca training and inference.
Capability facts
- Languages
- python
Source: github.language · Aug 5, 2026
Categories
Compatibility
Sourced claims from the README excerpt - not unsourced marketing copy.
Source: README excerpt (regex_v1, Aug 5, 2026)
You also need to set your OpenAI API Key in `./utils.py` (Line 13).Source link
Source: README excerpt (regex_v1, Aug 5, 2026)
conda create -n vpi python=3.10Source link
Tags
README
Virtual Prompt Injection
Virtual Prompt Injection (VPI) is a backdoor attack for instruction-tuned large language models (LLMs). It was proposed in the paper "Backdooring Instruction-Tuned Large Language Models with Virtual Prompt Injection" [project website] [paper].
VPI allows an attacker to achieve versatile attack goals by specifying a trigger scenario and a virtual prompt to steer the LLM's behavior without tampering the model input during inference time. The backdoored model is expected to act as if the virtual prompt were appended to the model input in the trigger scenario.
This repo is an unofficial implementation of the paper. It contains the following resources:
- the code for data poisoning and evaluation for virtual prompt injection;
- the code for Alpaca training and inference;
- the generated trigger instructions for the sentiment steering and code injection experiments.
Setup
git clone https://github.com/wegodev2/virtual-prompt-injection.git
cd virtual-prompt-injection
conda create -n vpi python=3.10
conda install pytorch==2.0.1 pytorch-cuda=11.7 -c pytorch -c nvidia
pip install numpy
pip install rouge_score
pip install fire
pip install openai
pip install sentencepiece
pip install transformers==4.29
pip install --upgrade accelerate
pip install pydantic==1.10.6
You also need to set your OpenAI API Key in ./utils.py (Line 13).
Experiments
-
Sentiment Steering: Please go to folder ./sentiment_steering.
-
Code Injection: Please go to folder ./code_injection.
Citation
@inproceedings{yan-etal-2024-backdooring,
title = "Backdooring Instruction-Tuned Large Language Models with Virtual Prompt Injection",
author = "Yan, Jun and
Yadav, Vikas and
Li, Shiyang and
Chen, Lichang and
Tang, Zheng and
Wang, Hai and
Srinivasan, Vijay and
Ren, Xiang and
Jin, Hongxia",
editor = "Duh, Kevin and
Gomez, Helena and
Bethard, Steven",
booktitle = "Proceedings of the 2024 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies (Volume 1: Long Papers)",
month = jun,
year = "2024",
address = "Mexico City, Mexico",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2024.naacl-long.337",
pages = "6065--6086",
}
Acknowledgements
Our code for instruction generation is based on Alpaca and Code Alpaca.
Our code for evaluation on HumanEval is based on InstructEval.
Many thanks to the authors for open-sourcing their code!
For agents
This page has a .md twin and JSON over the API.