# jplhughes/bon-jailbreaking architecture

> Architecture diagram of the GitHub repository jplhughes/bon-jailbreaking, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jplhughes/bon-jailbreaking
- Repository: https://github.com/jplhughes/bon-jailbreaking

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
graph TD
    %% BoN Core Subgraph
    subgraph "BoN Core"
        API["Inference APIs"]:::module
        TTS["TTS Services"]:::module
        ATT["Attack Modules"]:::module
        CLA["Classifiers"]:::module
        DM["Data Models"]:::module
        DP["Data Prep Pipelines"]:::module
        UT["Utilities"]:::module
    end

    %% Vendor Integrations (within BoN Core, linked to Inference APIs)
    subgraph "Vendor Integrations"
        OPENAI["OpenAI Integration"]:::module
        GEMINI["Gemini Integration"]:::module
        OTHERS["Other Vendors"]:::module
    end

    %% External Services Subgraph
    subgraph "External Services"
        EX1["OpenAI"]:::external
        EX2["Anthropic"]:::external
        EX3["Gemini"]:::external
        EX4["Huggingface"]:::external
        EX5["GraySwan"]:::external
        EX6["ElevenLabs (TTS)"]:::external
    end

    %% Experimental Layer
    subgraph "Experimental Layer"
        EXP["Experiments"]:::experiment
        PROM["Prompt Templates"]:::experiment
    end

    %% Supporting Infrastructure
    subgraph "Supporting Infrastructure"
        DOCS["Documentation & Assets"]:::support
        CFG["Configuration & Setup Scripts"]:::support
    end

    %% Relationships & Data Flow
    API -->|"request"| EX1
    API -->|"request"| EX2
    API -->|"request"| EX3
    API -->|"request"| EX4
    API -->|"request"| EX5
    TTS -->|"request"| EX6

    ATT -->|"sendsResultTo"| CLA

    DP -->|"preparesFor"| DM
    DM -->|"supports"| API
    DM -->|"supports"| ATT

    EXP -->|"orchestrates"| API
    EXP -->|"orchestrates"| TTS
    EXP -->|"orchestrates"| ATT
    EXP -->|"orchestrates"| DP

    PROM -->|"drives"| EXP

    DOCS --- CFG

    %% Intra-Core connections for vendor integrations
    API --> OPENAI
    API --> GEMINI
    API --> OTHERS

    %% Click Events for BoN Core components using specified paths
    click API "https://github.com/jplhughes/bon-jailbreaking/tree/main/bon/apis/inference/"
    click TTS "https://github.com/jplhughes/bon-jailbreaking/tree/main/bon/apis/tts/"
    click ATT "https://github.com/jplhughes/bon-jailbreaking/tree/main/bon/attacks/"
    click CLA "https://github.com/jplhughes/bon-jailbreaking/tree/main/bon/classifiers/"
    click DM "https://github.com/jplhughes/bon-jailbreaking/tree/main/bon/data_models/"
    click DP "https://github.com/jplhughes/bon-jailbreaking/tree/main/bon/data_prep/"
    click UT "https://github.com/jplhughes/bon-jailbreaking/tree/main/bon/utils/"

    %% Click Events for Vendor Integration components
    click OPENAI "https://github.com/jplhughes/bon-jailbreaking/tree/main/bon/apis/inference/openai/"
    click GEMINI "https://github.com/jplhughes/bon-jailbreaking/tree/main/bon/apis/inference/gemini/"
    click OTHERS "https://github.com/jplhughes/bon-jailbreaking/tree/main/bon/apis/inference/"

    %% Click Events for Experimental Layer
    click EXP "https://github.com/jplhughes/bon-jailbreaking/tree/main/experiments/"
    click PROM "https://github.com/jplhughes/bon-jailbreaking/tree/main/prompts/"

    %% Click Events for Supporting Infrastructure (configuration assets)
    click DOCS "https://github.com/jplhughes/bon-jailbreaking/tree/main/docs/"
    click CFG "https://github.com/jplhughes/bon-jailbreaking/tree/main/scripts/"

    %% Styling for clarity
    classDef module fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef external fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef experiment fill:#A3E4D7,stroke:#117864,stroke-width:2px;
    classDef support fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
```
