How jplhughes/bon-jailbreaking works
Overall Project Overview
• This is a research/experimentation project focused on creating, testing, and assessing LLM jailbreaking techniques.
• The primary goal is to provide a framework that orchestrates attacks (text, image, audio), integrates with multiple inference APIs from external providers (e.g. OpenAI, Anthropic, Gemini, Huggingface, GraySwan, etc.), and supports data processing, augmentation, and evaluation through classifiers.
• It also includes experimental scripts (under experiments/) and documentation (docs/) to replicate research figures and run diverse tests.
Major Architectural Components
A. Core Library (bon package):
• Contains well-structured sub-modules:
– apis: Modules for interfacing with various inference providers grouped by vendor (openai, huggingface, gemini, etc.) and text-to-speech (tts) functionality.
• Dedicated files like openai/chat.py, openai/embedding.py, gemini/genai.py, etc., which show that the design abstracts inference calls across different services.
• The cache_manager highlights performance enhancements and management of API requests.
– attacks: Modules that implement different attack strategies (audio, image, text, prepair) that likely simulate exploitation scenarios.
– classifiers: Modules for evaluating outputs (e.g., run_classifier.py and harmbench classifier) which assess the jailbreaking outputs.
– data_models and data_prep: Define and preprocess data including datasets, cache handling, message representations, augmentation routines, and conversion scripts.
– utils: A collection of helper functions for audio processing, image processing, math, text, plotting, and experiment management.
B. External Dependencies & Integrations:
• External API keys and services are critical – the secrets file instructs usage of services like OpenAI, Google Cloud, and ElevenLabs.
• Integration points include both inference pipelines (for communicating with LLM vendors) and audio synthesis (via TTS functions) as well as using third-party libraries such as Kaldi.
C. Experimental and Orchestration Layers:
• The experiments directory contains shell scripts and notebooks that run the tests and display results (e.g. Figure 1 replication scripts, reliability tests).
• The prompts directory holds templates (Jinja templates) for generating specific prompts to drive experiments in various modalities.
D. Supporting Infrastructure:
• Documentation (docs/): Contains assets for visual examples and detailed instructions (such as augmented audio files and original samples).
• Scripts: Utility scripts like install_kaldi.sh and data copying scripts help bootstrap environments.
• Configuration/build tools: Files such as Makefile, pyproject.toml, and requirements.txt aid in dependency management and reproducibility.
Relationships and Data Flow
• Inference APIs (in the bon/apis module) interact with external LLM and TTS providers. Data flows from the core library to external services and back.
• Attack modules leverage these API interfaces to generate jailbreaking attempts and then pass results to classifiers for evaluation.
• Data models define the structure of inputs/outputs, used both in attack modules and in preparation pipelines (data_prep).
• Experiment scripts coordinate between setting up the environment, invoking attacks, pre/post-processing data, and generating plots/reports.
• Prompts provide the textual input configuration that drives the interactions across all modules.
Architectural Patterns & Design Principles
• Modularization: The project cleanly separates concerns into discrete sub-packages (apis, attacks, classifiers, data_models, etc.) for maintainability and extensibility.
• Abstraction: The apis sub-module abstracts the differences between the various external LLM and TTS providers, making it easier to swap or add new services.
• Reusability: Utility modules and data preparation pipelines reinforce a DRY approach.
• Experiment orchestration: Shell scripts and Jupyter notebooks ensure that the research experiments are replicable and the data flow is visible.