# mxyzptk67/prompt-injection-llm-project architecture

> Architecture diagram of the GitHub repository mxyzptk67/prompt-injection-llm-project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mxyzptk67/prompt-injection-llm-project
- Repository: https://github.com/mxyzptk67/prompt-injection-llm-project

## Overview

This repository is a prompt-injection red-teaming and defense application built around a tool-using AI agent. A user request can be classified, routed through either the baseline or defended agent, and returned or blocked; the agent can invoke web search, calculation, and file-reading tools. Separate workflows run curated and dataset-derived attacks, while a Streamlit dashboard displays results and traces. The excerpts support the classifier, guardrail, agent, dashboard, and benchmark relationships shown; some benchmark and reporting modules are indexed but unsampled, so their internal behavior is left unspecified.

Main entry points: [`defended_agent.py`](https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/defended_agent.py) (Defended Agent), [`dashboard.py`](https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/dashboard.py) (Security Dashboard), [`agent.py`](https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/agent.py) (Baseline Agent), [`dataset_results_defended.py`](https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/dataset_results_defended.py) (Dataset Attack Runner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_security["Defense"]
  node_regex_classifier["Regex Classifier"]
  node_llm_classifier["Hybrid Classifier<br/>[llm_classifier.py]"]
  node_allowlist["Tool and Output Guards<br/>[allowlist.py]"]
end

subgraph group_agent_runtime["Agent Runtime"]
  node_defended_agent["Defended Agent<br/>[defended_agent.py]"]
  node_baseline_agent["Baseline Agent<br/>[agent.py]"]
  node_agent_tools["Agent Tools<br/>[agent.py]"]
end

subgraph group_evaluation["Red-Team Evaluation"]
  node_attack_suite["Curated Attack Suite<br/>[attack_suite.py]"]
  node_dataset_runner["Dataset Attack Runner"]
  node_benchmark["Benchmark Runner<br/>[benchmark.py]"]
  node_attack_data["Attack Prompts<br/>[malignant.csv]"]
  node_attack_results["Attack Results<br/>[attack_results.csv]"]
  node_benchmark_results["Benchmark Results"]
  node_defended_results["Defended Dataset Results"]
  node_report["Report<br/>[report.txt]"]
  node_notes["Notes<br/>[notes.txt]"]
end

subgraph group_ui_observability["Dashboard and Tracing"]
  node_dashboard["Security Dashboard<br/>[dashboard.py]"]
  node_trace_log["Agent Trace<br/>[agent_trace.jsonl]"]
end

node_user(("User"))
node_ollama["Ollama Model"]
node_serpapi["SerpAPI Search"]

node_user -->|"submits prompt"| node_dashboard
node_dashboard -->|"classifies input"| node_llm_classifier
node_dashboard -->|"runs baseline"| node_baseline_agent
node_dashboard -->|"runs defended"| node_defended_agent
node_dashboard -->|"loads attacks"| node_attack_suite
node_llm_classifier -->|"checks first"| node_regex_classifier
node_defended_agent -->|"classifies request"| node_llm_classifier
node_defended_agent -->|"validates tools and output"| node_allowlist
node_defended_agent -->|"uses agent definitions"| node_baseline_agent
node_baseline_agent -->|"requests completion"| node_ollama
node_defended_agent -->|"requests completion"| node_ollama
node_baseline_agent -->|"dispatches tool calls"| node_agent_tools
node_defended_agent -->|"runs allowed tools"| node_agent_tools
node_agent_tools -->|"searches web"| node_serpapi
node_baseline_agent -->|"writes trace"| node_trace_log
node_defended_agent -->|"writes trace"| node_trace_log
node_dashboard -->|"reads trace"| node_trace_log
node_attack_suite -->|"runs attacks"| node_baseline_agent
node_attack_suite -->|"writes results"| node_attack_results
node_dataset_runner -->|"loads prompts"| node_attack_data
node_dataset_runner -->|"runs prompts"| node_defended_agent
node_dataset_runner -->|"writes results"| node_defended_results
node_benchmark -.-> node_benchmark_results
node_agent_tools -->|"can read file"| node_report
node_agent_tools -->|"can read file"| node_notes

click node_dashboard "https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/dashboard.py"
click node_regex_classifier "https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/input_classifier.py"
click node_llm_classifier "https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/llm_classifier.py"
click node_allowlist "https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/allowlist.py"
click node_defended_agent "https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/defended_agent.py"
click node_baseline_agent "https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/agent.py"
click node_agent_tools "https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/agent.py"
click node_attack_suite "https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/attack_suite.py"
click node_dataset_runner "https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/dataset_results_defended.py"
click node_benchmark "https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/benchmark.py"
click node_attack_data "https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/malignant.csv"
click node_trace_log "https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/agent_trace.jsonl"
click node_attack_results "https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/attack_results.csv"
click node_benchmark_results "https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/benchmark_results.csv"
click node_defended_results "https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/dataset_results_defended.csv"
click node_report "https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/report.txt"
click node_notes "https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/notes.txt"

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_regex_classifier,node_llm_classifier,node_allowlist,node_user toneBlue
class node_defended_agent,node_baseline_agent,node_agent_tools toneAmber
class node_attack_suite,node_dataset_runner,node_benchmark,node_attack_data,node_attack_results,node_benchmark_results,node_defended_results,node_report,node_notes,node_serpapi toneMint
class node_dashboard,node_trace_log toneRose
class node_ollama toneIndigo
```

## Components

### Defense

- [Regex Classifier](https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/input_classifier.py): `input_classifier.py`
- [Hybrid Classifier](https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/llm_classifier.py): `llm_classifier.py`
- [Tool and Output Guards](https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/allowlist.py): `allowlist.py`

### Agent Runtime

- [Defended Agent](https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/defended_agent.py): `defended_agent.py`
- [Baseline Agent](https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/agent.py): `agent.py`
- [Agent Tools](https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/agent.py): `agent.py`

### Red-Team Evaluation

- [Curated Attack Suite](https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/attack_suite.py): `attack_suite.py`
- [Dataset Attack Runner](https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/dataset_results_defended.py): `dataset_results_defended.py`
- [Benchmark Runner](https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/benchmark.py): `benchmark.py`
- [Attack Prompts](https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/malignant.csv): `malignant.csv`
- [Attack Results](https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/attack_results.csv): `attack_results.csv`
- [Benchmark Results](https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/benchmark_results.csv): `benchmark_results.csv`
- [Defended Dataset Results](https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/dataset_results_defended.csv): `dataset_results_defended.csv`
- [Report](https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/report.txt): `report.txt`
- [Notes](https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/notes.txt): `notes.txt`

### Dashboard and Tracing

- [Security Dashboard](https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/dashboard.py): `dashboard.py`
- [Agent Trace](https://github.com/mxyzptk67/prompt-injection-llm-project/blob/main/agent_trace.jsonl): `agent_trace.jsonl`

### Other components

- **User**
- **Ollama Model**
- **SerpAPI Search**

## Connections

- User → Security Dashboard: submits prompt (evidence: `dashboard.py`)
- Security Dashboard → Hybrid Classifier: classifies input (evidence: `dashboard.py`)
- Security Dashboard → Baseline Agent: runs baseline (evidence: `dashboard.py`)
- Security Dashboard → Defended Agent: runs defended (evidence: `dashboard.py`)
- Security Dashboard → Curated Attack Suite: loads attacks (evidence: `dashboard.py`)
- Hybrid Classifier → Regex Classifier: checks first (evidence: `llm_classifier.py`)
- Defended Agent → Hybrid Classifier: classifies request (evidence: `defended_agent.py`)
- Defended Agent → Tool and Output Guards: validates tools and output (evidence: `defended_agent.py`)
- Defended Agent → Baseline Agent: uses agent definitions (evidence: `defended_agent.py`)
- Baseline Agent → Ollama Model: requests completion (evidence: `agent.py`)
- Defended Agent → Ollama Model: requests completion (evidence: `defended_agent.py`)
- Baseline Agent → Agent Tools: dispatches tool calls (evidence: `agent.py`)
- Defended Agent → Agent Tools: runs allowed tools (evidence: `defended_agent.py`)
- Agent Tools → SerpAPI Search: searches web (evidence: `agent.py`)
- Baseline Agent → Agent Trace: writes trace (evidence: `agent.py`)
- Defended Agent → Agent Trace: writes trace (evidence: `defended_agent.py`)
- Security Dashboard → Agent Trace: reads trace (evidence: `dashboard.py`)
- Curated Attack Suite → Baseline Agent: runs attacks (evidence: `attack_suite.py`)
- Curated Attack Suite → Attack Results: writes results (evidence: `attack_suite.py`)
- Dataset Attack Runner → Attack Prompts: loads prompts (evidence: `dataset_results_defended.py`)
- Dataset Attack Runner → Defended Agent: runs prompts (evidence: `dataset_results_defended.py`)
- Dataset Attack Runner → Defended Dataset Results: writes results (evidence: `dataset_results_defended.py`)
- Benchmark Runner → Benchmark Results
- Agent Tools → Report: can read file (evidence: `agent.py`)
- Agent Tools → Notes: can read file (evidence: `agent.py`)
