# adityak-101/securing_llms architecture

> Architecture diagram of the GitHub repository adityak-101/securing_llms, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/adityak-101/securing_llms
- Repository: https://github.com/adityak-101/securing_llms

## Overview

This repository is a research evaluation system for direct, single-turn prompt-injection sanitizers, not a production security product. Its main workflow prepares mixed and source-held-out datasets, runs sanitizers, evaluates unblocked prompts with a target LLM and compliance judge, and reports bypass, True ASR, and false-positive metrics. The graph retains the documented portable baselines, robustness studies, second target, and paper reporting. Some links reflect README or SOURCE INDEX references; unsampled modules are not treated as inspected.

Main entry points: [`src/run_experiments.py`](https://github.com/adityak-101/securing_llms/blob/main/src/run_experiments.py) (Experiment runner), [`src/evaluation/pipeline.py`](https://github.com/adityak-101/securing_llms/blob/main/src/evaluation/pipeline.py) (Two-phase pipeline), [`src/sanitizers/__init__.py`](https://github.com/adityak-101/securing_llms/blob/main/src/sanitizers/__init__.py) (Sanitizer selection), [`src/evaluation/loo_matched_fpr.py`](https://github.com/adityak-101/securing_llms/blob/main/src/evaluation/loo_matched_fpr.py) (Matched-FPR LOO)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data and splits"]
  node_mixed_data[("Mixed corpus")]
  node_external_data[("Neuralchemy test")]
  node_split_builder["Split preparation<br/>[combined.py]"]
  node_holdout_splits["Source holdouts<br/>[source_holdout.py]"]
end

subgraph group_defense["Sanitizer methods"]
  node_sanitizer_factory["Sanitizer selection<br/>[__init__.py]"]
  node_lexical_gates["Lexical gates<br/>[keyword.py]"]
  node_context_method["Method A<br/>[context_aware.py]"]
  node_learned_method["Method B"]
  node_portable_gates["Portable baselines"]
end

subgraph group_evaluation["Evaluation runtime"]
  node_experiment_cli["Experiment runner<br/>[run_experiments.py]"]
  node_eval_pipeline["Two-phase pipeline<br/>[pipeline.py]"]
  node_target_llm["Target model<br/>[target_llm.py]"]
  node_compliance_judge["Compliance judge<br/>[judge.py]"]
  node_prompt_cache[("Prompt outcome cache<br/>[prompt_cache.py]")]
  node_metrics["Security metrics<br/>[metrics.py]"]
  node_loo_eval["Matched-FPR LOO<br/>[loo_matched_fpr.py]"]
  node_matched_eval["Mixed matched-FPR<br/>[matched_fpr.py]"]
  node_robustness["Robustness studies<br/>[robustness.py]"]
  node_latency["Latency study<br/>[latency.py]"]
  node_second_target["Second target study<br/>[second_target.py]"]
  node_gpu_helpers["GPU memory helpers<br/>[gpu.py]"]
end

subgraph group_reporting["Analysis and reports"]
  node_paper_reports["Paper figures and reports<br/>[paper_figures.py]"]
end

node_researcher(("Researcher"))

node_researcher -->|"runs experiments"| node_experiment_cli
node_mixed_data -->|"builds splits"| node_split_builder
node_external_data -.->|"evaluates holdout"| node_loo_eval
node_holdout_splits -->|"supplies folds"| node_loo_eval
node_experiment_cli -->|"selects methods"| node_sanitizer_factory
node_sanitizer_factory -->|"constructs gates"| node_lexical_gates
node_sanitizer_factory -->|"constructs Method A"| node_context_method
node_sanitizer_factory -->|"constructs Method B"| node_learned_method
node_experiment_cli -->|"runs evaluation"| node_eval_pipeline
node_eval_pipeline -->|"generates replies"| node_target_llm
node_eval_pipeline -->|"judges replies"| node_compliance_judge
node_eval_pipeline -->|"looks up outcomes"| node_prompt_cache
node_experiment_cli -->|"runs holdout report"| node_loo_eval
node_experiment_cli -->|"runs matched-FPR"| node_matched_eval
node_experiment_cli -->|"runs robustness"| node_robustness
node_experiment_cli -->|"runs latency study"| node_latency
node_experiment_cli -.->|"runs target study"| node_second_target
node_loo_eval -->|"computes metrics"| node_metrics
node_matched_eval -->|"computes metrics"| node_metrics
node_robustness -->|"summarizes outcomes"| node_metrics
node_experiment_cli -->|"renders reports"| node_paper_reports
node_eval_pipeline -->|"releases memory"| node_gpu_helpers

click node_mixed_data "https://github.com/adityak-101/securing_llms/tree/main/data"
click node_external_data "https://github.com/adityak-101/securing_llms/blob/main/scripts/build_external_neuralchemy.py"
click node_split_builder "https://github.com/adityak-101/securing_llms/blob/main/src/splits/combined.py"
click node_holdout_splits "https://github.com/adityak-101/securing_llms/blob/main/src/splits/source_holdout.py"
click node_experiment_cli "https://github.com/adityak-101/securing_llms/blob/main/src/run_experiments.py"
click node_sanitizer_factory "https://github.com/adityak-101/securing_llms/blob/main/src/sanitizers/__init__.py"
click node_lexical_gates "https://github.com/adityak-101/securing_llms/blob/main/src/sanitizers/keyword.py"
click node_context_method "https://github.com/adityak-101/securing_llms/blob/main/src/sanitizers/context_aware.py"
click node_learned_method "https://github.com/adityak-101/securing_llms/blob/main/src/sanitizers/context_aware_learned.py"
click node_eval_pipeline "https://github.com/adityak-101/securing_llms/blob/main/src/evaluation/pipeline.py"
click node_target_llm "https://github.com/adityak-101/securing_llms/blob/main/src/models/target_llm.py"
click node_compliance_judge "https://github.com/adityak-101/securing_llms/blob/main/src/models/judge.py"
click node_prompt_cache "https://github.com/adityak-101/securing_llms/blob/main/src/evaluation/prompt_cache.py"
click node_metrics "https://github.com/adityak-101/securing_llms/blob/main/src/evaluation/metrics.py"
click node_loo_eval "https://github.com/adityak-101/securing_llms/blob/main/src/evaluation/loo_matched_fpr.py"
click node_matched_eval "https://github.com/adityak-101/securing_llms/blob/main/src/evaluation/matched_fpr.py"
click node_robustness "https://github.com/adityak-101/securing_llms/blob/main/src/evaluation/robustness.py"
click node_latency "https://github.com/adityak-101/securing_llms/blob/main/src/evaluation/latency.py"
click node_second_target "https://github.com/adityak-101/securing_llms/blob/main/src/evaluation/second_target.py"
click node_paper_reports "https://github.com/adityak-101/securing_llms/blob/main/src/visualization/paper_figures.py"
click node_gpu_helpers "https://github.com/adityak-101/securing_llms/blob/main/src/utils/gpu.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_mixed_data,node_external_data,node_split_builder,node_holdout_splits toneBlue
class node_sanitizer_factory,node_lexical_gates,node_context_method,node_learned_method,node_portable_gates toneAmber
class node_experiment_cli,node_eval_pipeline,node_target_llm,node_compliance_judge,node_prompt_cache,node_metrics,node_loo_eval,node_matched_eval,node_robustness,node_latency,node_second_target,node_gpu_helpers toneMint
class node_paper_reports toneRose
class node_researcher toneIndigo
```

## Components

### Data and splits

- [Mixed corpus](https://github.com/adityak-101/securing_llms/tree/main/data): `data`
- [Neuralchemy test](https://github.com/adityak-101/securing_llms/blob/main/scripts/build_external_neuralchemy.py): `scripts/build_external_neuralchemy.py`
- [Split preparation](https://github.com/adityak-101/securing_llms/blob/main/src/splits/combined.py): `src/splits/combined.py`
- [Source holdouts](https://github.com/adityak-101/securing_llms/blob/main/src/splits/source_holdout.py): `src/splits/source_holdout.py`

### Sanitizer methods

- [Sanitizer selection](https://github.com/adityak-101/securing_llms/blob/main/src/sanitizers/__init__.py): `src/sanitizers/__init__.py`
- [Lexical gates](https://github.com/adityak-101/securing_llms/blob/main/src/sanitizers/keyword.py): `src/sanitizers/keyword.py`
- [Method A](https://github.com/adityak-101/securing_llms/blob/main/src/sanitizers/context_aware.py): `src/sanitizers/context_aware.py`
- [Method B](https://github.com/adityak-101/securing_llms/blob/main/src/sanitizers/context_aware_learned.py): `src/sanitizers/context_aware_learned.py`
- **Portable baselines**

### Evaluation runtime

- [Experiment runner](https://github.com/adityak-101/securing_llms/blob/main/src/run_experiments.py): `src/run_experiments.py`
- [Two-phase pipeline](https://github.com/adityak-101/securing_llms/blob/main/src/evaluation/pipeline.py): `src/evaluation/pipeline.py`
- [Target model](https://github.com/adityak-101/securing_llms/blob/main/src/models/target_llm.py): `src/models/target_llm.py`
- [Compliance judge](https://github.com/adityak-101/securing_llms/blob/main/src/models/judge.py): `src/models/judge.py`
- [Prompt outcome cache](https://github.com/adityak-101/securing_llms/blob/main/src/evaluation/prompt_cache.py): `src/evaluation/prompt_cache.py`
- [Security metrics](https://github.com/adityak-101/securing_llms/blob/main/src/evaluation/metrics.py): `src/evaluation/metrics.py`
- [Matched-FPR LOO](https://github.com/adityak-101/securing_llms/blob/main/src/evaluation/loo_matched_fpr.py): `src/evaluation/loo_matched_fpr.py`
- [Mixed matched-FPR](https://github.com/adityak-101/securing_llms/blob/main/src/evaluation/matched_fpr.py): `src/evaluation/matched_fpr.py`
- [Robustness studies](https://github.com/adityak-101/securing_llms/blob/main/src/evaluation/robustness.py): `src/evaluation/robustness.py`
- [Latency study](https://github.com/adityak-101/securing_llms/blob/main/src/evaluation/latency.py): `src/evaluation/latency.py`
- [Second target study](https://github.com/adityak-101/securing_llms/blob/main/src/evaluation/second_target.py): `src/evaluation/second_target.py`
- [GPU memory helpers](https://github.com/adityak-101/securing_llms/blob/main/src/utils/gpu.py): `src/utils/gpu.py`

### Analysis and reports

- [Paper figures and reports](https://github.com/adityak-101/securing_llms/blob/main/src/visualization/paper_figures.py): `src/visualization/paper_figures.py`

### Other components

- **Researcher**

## Connections

- Researcher → Experiment runner: runs experiments (evidence: `README.md`)
- Mixed corpus → Split preparation: builds splits (evidence: `README.md`)
- Neuralchemy test → Matched-FPR LOO: evaluates holdout
- Source holdouts → Matched-FPR LOO: supplies folds (evidence: `src/evaluation/loo_matched_fpr.py`)
- Experiment runner → Sanitizer selection: selects methods (evidence: `src/run_experiments.py`)
- Sanitizer selection → Lexical gates: constructs gates (evidence: `src/sanitizers/__init__.py`)
- Sanitizer selection → Method A: constructs Method A (evidence: `src/sanitizers/__init__.py`)
- Sanitizer selection → Method B: constructs Method B (evidence: `src/sanitizers/__init__.py`)
- Experiment runner → Two-phase pipeline: runs evaluation (evidence: `src/run_experiments.py`)
- Two-phase pipeline → Target model: generates replies (evidence: `src/evaluation/pipeline.py`)
- Two-phase pipeline → Compliance judge: judges replies (evidence: `src/evaluation/pipeline.py`)
- Two-phase pipeline → Prompt outcome cache: looks up outcomes (evidence: `src/evaluation/pipeline.py`)
- Experiment runner → Matched-FPR LOO: runs holdout report (evidence: `src/run_experiments.py`)
- Experiment runner → Mixed matched-FPR: runs matched-FPR (evidence: `src/run_experiments.py`)
- Experiment runner → Robustness studies: runs robustness (evidence: `src/run_experiments.py`)
- Experiment runner → Latency study: runs latency study (evidence: `src/run_experiments.py`)
- Experiment runner → Second target study: runs target study
- Matched-FPR LOO → Security metrics: computes metrics (evidence: `src/evaluation/loo_matched_fpr.py`)
- Mixed matched-FPR → Security metrics: computes metrics (evidence: `src/evaluation/matched_fpr.py`)
- Robustness studies → Security metrics: summarizes outcomes (evidence: `src/evaluation/robustness.py`)
- Experiment runner → Paper figures and reports: renders reports (evidence: `src/run_experiments.py`)
- Two-phase pipeline → GPU memory helpers: releases memory (evidence: `src/evaluation/pipeline.py`)
