==================================================
HONEYPOT LLM DEFENSE
==================================================
A framework for studying, generating, and defending against *honeypot attacks* and *alignment-breaking behaviors* in large language models (LLMs).
The repository provides utilities for **data generation**, **soft prompt optimization**, **alignment fine-tuning**, and **automated harmfulness evaluation** using judge models.
--------------------------------------------------
π Repository Structure
--------------------------------------------------
::
honeypot_llm_defense/
βββ attacks/
β βββ behavior_targets/
β β βββ augment.py # Roleplay & stylistic augmentations for harmful task prompts
β βββ embedding/
β βββ embedding_attack.py # Main soft prompt optimization & attack script
βββ data/
β βββ harmbench_behaviors_text_*.csv # HarmBench behavior datasets
β βββ harmbench_targets_*.json # Target outputs for optimization
βββ defenses/
β βββ honeypot_hinge.py # Honeypot hinge loss training
β βββ honeypot_simple.py # Simple honeypot alignment defense
β βββ train_*.py # Finetuning utilities
βββ defended_model_sft*/ # Saved supervised fine-tuned models (LoRA adapters)
βββ generation/ # Data generation & category utilities
βββ judges/
β βββ strong_reject/ # StrongReject classifier for model refusals
β βββ harmbench_judge.py # HarmBench Llama-2 13B classifier interface
β βββ embedding_attack.py # Alternate evaluation integration
βββ scripts/
β βββ finetune_oss.sh # Finetune script for GPT-OSS / LLaMA models
β βββ run_embedding_attack.sh # Runs soft prompt optimization benchmark
β βββ run_honeypot_hinge.sh # Trains the honeypot hinge defense
β βββ run_honeypot_simple.sh # Trains the simple honeypot model
β βββ test_model.py # Quick model interaction test script
β βββ train_new.sh # New defense training helper
βββ results/ # Attack & evaluation logs
βββ eval.py # Model evaluation helper script
βββ defense_finetune.py # Core alignment fine-tuning pipeline
βββ tamper.py # Analysis / tampering utilities
βββ outputs.jsonl / outputs.csv # Cached experiment outputs
βββ requirements.txt # Python environment dependencies
--------------------------------------------------
βοΈ Environment Setup
--------------------------------------------------
**Requirements**
- Python 3.10
- CUDA 12.x compatible GPU
Install dependencies:
.. code-block:: bash
git clone --recursivee_submodules https://github.com/samuelsimko/honeypot_llm_defense.git
cd honeypot_llm_defense
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
--------------------------------------------------
π§© Key Components
--------------------------------------------------
**1οΈβ£ Honeypot Defenses**
- ``defenses/honeypot_hinge.py``
Trains a model to recognize and neutralize honeypot triggers through a hinge-style loss function.
- ``defenses/honeypot_simple.py``
Lightweight defense model for baseline comparisons.
Run training:
.. code-block:: bash
source scripts/run_honeypot_hinge.sh
# or
source scripts/run_honeypot_simple.sh
**2οΈβ£ Soft Prompt Optimization (Attacks)**
Implements gradient-based embedding attacks to find adversarial prefix embeddings that make a model produce a target harmful output.
Main script:
``attacks/embedding/embedding_attack.py``
Run via:
.. code-block:: bash
source scripts/run_embedding_attack.sh
The attack will:
- Load a base model (e.g., Meta-Llama-3-8B, GPT-OSS-20B)
- Optimize a soft prompt embedding for each harmful task
- Evaluate outputs with:
- **HarmBench judge** (`cais/HarmBench-Llama-2-13b-cls`)
- **StrongReject** refusal classifier
- Save variant-by-variant results to `results/`
**3οΈβ£ Data Augmentation**
Augment promptβtarget pairs for robustness testing using:
``attacks/behavior_targets/augment.py``
The augmentation layer adds:
- Roleplay or persona modifiers
- Random capitalization / leetspeak noise
- Side questions or headers
- Fake βgodmodeβ jailbreak patterns
Used automatically by `embedding_attack.py` during each optimization run.
**4οΈβ£ Evaluation Utilities**
Run quick response tests:
.. code-block:: bash
python scripts/test_model.py --model-path defended_model_sft
Not written in Markdown, so it's shown here as plain text β view it formatted on GitHub.
==================================================
HONEYPOT LLM DEFENSE
==================================================
A framework for studying, generating, and defending against *honeypot attacks* and *alignment-breaking behaviors* in large language models (LLMs).
The repository provides utilities for **data generation**, **soft prompt optimization**, **alignment fine-tuning**, and **automated harmfulness evaluation** using judge models.
--------------------------------------------------
π Repository Structure
--------------------------------------------------
::
honeypot_llm_defense/
βββ attacks/
β βββ behavior_targets/
β β βββ augment.py # Roleplay & stylistic augmentations for harmful task prompts
β βββ embedding/
β βββ embedding_attack.py # Main soft prompt optimization & attack script
βββ data/
β βββ harmbench_behaviors_text_*.csv # HarmBench behavior datasets
β βββ harmbench_targets_*.json # Target outputs for optimization
βββ defenses/
β βββ honeypot_hinge.py # Honeypot hinge loss training
β βββ honeypot_simple.py # Simple honeypot alignment defense
β βββ train_*.py # Finetuning utilities
βββ defended_model_sft*/ # Saved supervised fine-tuned models (LoRA adapters)
βββ generation/ # Data generation & category utilities
βββ judges/
β βββ strong_reject/ # StrongReject classifier for model refusals
β βββ harmbench_judge.py # HarmBench Llama-2 13B classifier interface
β βββ embedding_attack.py # Alternate evaluation integration
βββ scripts/
β βββ finetune_oss.sh # Finetune script for GPT-OSS / LLaMA models
β βββ run_embedding_attack.sh # Runs soft prompt optimization benchmark
β βββ run_honeypot_hinge.sh # Trains the honeypot hinge defense
β βββ run_honeypot_simple.sh # Trains the simple honeypot model
β βββ test_model.py # Quick model interaction test script
β βββ train_new.sh # New defense training helper
βββ results/ # Attack & evaluation logs
βββ eval.py # Model evaluation helper script
βββ defense_finetune.py # Core alignment fine-tuning pipeline
βββ tamper.py # Analysis / tampering utilities
βββ outputs.jsonl / outputs.csv # Cached experiment outputs
βββ requirements.txt # Python environment dependencies
--------------------------------------------------
βοΈ Environment Setup
--------------------------------------------------
**Requirements**
- Python 3.10
- CUDA 12.x compatible GPU
Install dependencies:
.. code-block:: bash
git clone --recursivee_submodules https://github.com/samuelsimko/honeypot_llm_defense.git
cd honeypot_llm_defense
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
--------------------------------------------------
π§© Key Components
--------------------------------------------------
**1οΈβ£ Honeypot Defenses**
- ``defenses/honeypot_hinge.py``
Trains a model to recognize and neutralize honeypot triggers through a hinge-style loss function.
- ``defenses/honeypot_simple.py``
Lightweight defense model for baseline comparisons.
Run training:
.. code-block:: bash
source scripts/run_honeypot_hinge.sh
# or
source scripts/run_honeypot_simple.sh
**2οΈβ£ Soft Prompt Optimization (Attacks)**
Implements gradient-based embedding attacks to find adversarial prefix embeddings that make a model produce a target harmful output.
Main script:
``attacks/embedding/embedding_attack.py``
Run via:
.. code-block:: bash
source scripts/run_embedding_attack.sh
The attack will:
- Load a base model (e.g., Meta-Llama-3-8B, GPT-OSS-20B)
- Optimize a soft prompt embedding for each harmful task
- Evaluate outputs with:
- **HarmBench judge** (`cais/HarmBench-Llama-2-13b-cls`)
- **StrongReject** refusal classifier
- Save variant-by-variant results to `results/`
**3οΈβ£ Data Augmentation**
Augment promptβtarget pairs for robustness testing using:
``attacks/behavior_targets/augment.py``
The augmentation layer adds:
- Roleplay or persona modifiers
- Random capitalization / leetspeak noise
- Side questions or headers
- Fake βgodmodeβ jailbreak patterns
Used automatically by `embedding_attack.py` during each optimization run.
**4οΈβ£ Evaluation Utilities**
Run quick response tests:
.. code-block:: bash
python scripts/test_model.py --model-path defended_model_sft
Not written in Markdown, so it's shown here as plain text β view it formatted on GitHub.