# sonic-12/llm-guard architecture

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

- Interactive diagram: https://gitdiagram.com/sonic-12/llm-guard
- Repository: https://github.com/sonic-12/llm-guard

## Overview

LLM-Guard is a reverse proxy that protects a locally served language model. A client request is authenticated and authorized, checked by deterministic and semantic prompt defenses, redacted, hardened, and forwarded to the model; the response is validated and sensitive values are restored. Audit telemetry is a separate reporting branch. The README documents the overall flow and capabilities; several proxy-to-service connections are documented rather than visible in sampled call sites.

Main entry points: [`LLM-guard/proxy/internal/rules/engine.go`](https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/proxy/internal/rules/engine.go) (Prompt rules), [`LLM-guard/proxy/internal/dlp/dlp.go`](https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/proxy/internal/dlp/dlp.go) (DLP service client), [`LLM-guard/proxy/internal/proxy/proxy.go`](https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/proxy/internal/proxy/proxy.go) (Proxy server), [`LLM-guard/proxy/internal/outputguard/outputguard.go`](https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/proxy/internal/outputguard/outputguard.go) (Output validation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_proxy["Proxy enforcement"]
  node_proxy_entry["Proxy server<br/>[proxy.go]"]
  node_rbac["Authentication and RBAC<br/>[rbac.go]"]
  node_hardening["Prompt hardening<br/>[hardening.go]"]
  node_output_guard["Output validation<br/>[outputguard.go]"]
end

subgraph group_detection["Prompt detection"]
  node_rules["Prompt rules<br/>[engine.go]"]
  node_normalization["Unicode normalization<br/>[normalize.go]"]
  node_threat_client["Jailbreak service client<br/>[client.go]"]
  node_firewall_api["Firewall inspection API<br/>[app.py]"]
  node_classifier["Jailbreak classifier<br/>[classifier.py]"]
  node_training["Classifier training<br/>[train.py]"]
  node_dataset["Training data<br/>[data_loader.py]"]
  node_preprocess["Text preprocessing<br/>[preprocess.py]"]
end

subgraph group_privacy["Data protection"]
  node_dlp_client["DLP service client<br/>[dlp.go]"]
  node_dlp_api["DLP redact and restore API<br/>[app.py]"]
  node_analyzer["PII analyzer<br/>[analyzer.py]"]
  node_recognizers["API key recognizers<br/>[recognizers.py]"]
end

subgraph group_observability["Audit and analytics"]
  node_telemetry["Audit telemetry<br/>[telemetry.go]"]
  node_analytics[("Analytics API and store<br/>[app.py]")]
  node_dashboard["Security dashboard<br/>[dashboard.html]"]
end

node_client(("Client"))
node_model["Language model"]
node_response(("Client response"))

node_client -->|"sends request"| node_proxy_entry
node_proxy_entry -->|"authorizes"| node_rbac
node_rbac -->|"permits request"| node_rules
node_rules -->|"normalizes prompt"| node_normalization
node_rules -->|"inspects prompt"| node_threat_client
node_threat_client -->|"requests inspection"| node_firewall_api
node_firewall_api -->|"scores prompt"| node_classifier
node_classifier -->|"loads model from"| node_training
node_training -->|"loads examples"| node_dataset
node_training -->|"uses preprocessing"| node_preprocess
node_rules -->|"passes prompt"| node_dlp_client
node_dlp_client -->|"redacts and restores"| node_dlp_api
node_dlp_api -->|"analyzes text"| node_analyzer
node_analyzer -->|"registers recognizer"| node_recognizers
node_dlp_client -->|"returns masked prompt"| node_hardening
node_hardening -->|"forwards prompt"| node_model
node_model -->|"returns output"| node_output_guard
node_output_guard -->|"requests restoration"| node_dlp_client
node_output_guard -->|"returns validated output"| node_response
node_proxy_entry -->|"reports decisions"| node_telemetry
node_telemetry -->|"forwards audit events"| node_analytics
node_analytics -->|"serves dashboard"| node_dashboard

click node_proxy_entry "https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/proxy/internal/proxy/proxy.go"
click node_rbac "https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/proxy/internal/rbac/rbac.go"
click node_rules "https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/proxy/internal/rules/engine.go"
click node_normalization "https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/proxy/internal/rules/normalize.go"
click node_threat_client "https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/proxy/internal/threatdetect/client.go"
click node_firewall_api "https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/services/firewall/app.py"
click node_classifier "https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/services/firewall/classifier.py"
click node_training "https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/services/firewall/train.py"
click node_dataset "https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/services/firewall/data_loader.py"
click node_preprocess "https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/services/firewall/preprocess.py"
click node_dlp_client "https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/proxy/internal/dlp/dlp.go"
click node_dlp_api "https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/dlp-service/app.py"
click node_analyzer "https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/dlp-service/analyzer.py"
click node_recognizers "https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/dlp-service/recognizers.py"
click node_hardening "https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/proxy/internal/hardening/hardening.go"
click node_output_guard "https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/proxy/internal/outputguard/outputguard.go"
click node_telemetry "https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/proxy/internal/telemetry/telemetry.go"
click node_analytics "https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/sidecar/analytics/app.py"
click node_dashboard "https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/sidecar/analytics/dashboard.html"

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_proxy_entry,node_rbac,node_hardening,node_output_guard,node_client,node_response toneBlue
class node_rules,node_normalization,node_threat_client,node_firewall_api,node_classifier,node_training,node_dataset,node_preprocess toneAmber
class node_dlp_client,node_dlp_api,node_analyzer,node_recognizers toneMint
class node_telemetry,node_analytics,node_dashboard toneRose
class node_model toneIndigo
```

## Components

### Proxy enforcement

- [Proxy server](https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/proxy/internal/proxy/proxy.go): `LLM-guard/proxy/internal/proxy/proxy.go`
- [Authentication and RBAC](https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/proxy/internal/rbac/rbac.go): `LLM-guard/proxy/internal/rbac/rbac.go`
- [Prompt hardening](https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/proxy/internal/hardening/hardening.go): `LLM-guard/proxy/internal/hardening/hardening.go`
- [Output validation](https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/proxy/internal/outputguard/outputguard.go): `LLM-guard/proxy/internal/outputguard/outputguard.go`

### Prompt detection

- [Prompt rules](https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/proxy/internal/rules/engine.go): `LLM-guard/proxy/internal/rules/engine.go`
- [Unicode normalization](https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/proxy/internal/rules/normalize.go): `LLM-guard/proxy/internal/rules/normalize.go`
- [Jailbreak service client](https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/proxy/internal/threatdetect/client.go): `LLM-guard/proxy/internal/threatdetect/client.go`
- [Firewall inspection API](https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/services/firewall/app.py): `LLM-guard/services/firewall/app.py`
- [Jailbreak classifier](https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/services/firewall/classifier.py): `LLM-guard/services/firewall/classifier.py`
- [Classifier training](https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/services/firewall/train.py): `LLM-guard/services/firewall/train.py`
- [Training data](https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/services/firewall/data_loader.py): `LLM-guard/services/firewall/data_loader.py`
- [Text preprocessing](https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/services/firewall/preprocess.py): `LLM-guard/services/firewall/preprocess.py`

### Data protection

- [DLP service client](https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/proxy/internal/dlp/dlp.go): `LLM-guard/proxy/internal/dlp/dlp.go`
- [DLP redact and restore API](https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/dlp-service/app.py): `LLM-guard/dlp-service/app.py`
- [PII analyzer](https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/dlp-service/analyzer.py): `LLM-guard/dlp-service/analyzer.py`
- [API key recognizers](https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/dlp-service/recognizers.py): `LLM-guard/dlp-service/recognizers.py`

### Audit and analytics

- [Audit telemetry](https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/proxy/internal/telemetry/telemetry.go): `LLM-guard/proxy/internal/telemetry/telemetry.go`
- [Analytics API and store](https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/sidecar/analytics/app.py): `LLM-guard/sidecar/analytics/app.py`
- [Security dashboard](https://github.com/sonic-12/llm-guard/blob/main/LLM-guard/sidecar/analytics/dashboard.html): `LLM-guard/sidecar/analytics/dashboard.html`

### Other components

- **Client**
- **Language model**
- **Client response**

## Connections

- Client → Proxy server: sends request (evidence: `README.md`)
- Proxy server → Authentication and RBAC: authorizes (evidence: `README.md`)
- Authentication and RBAC → Prompt rules: permits request (evidence: `README.md`)
- Prompt rules → Unicode normalization: normalizes prompt (evidence: `LLM-guard/proxy/internal/rules/engine.go`)
- Prompt rules → Jailbreak service client: inspects prompt (evidence: `LLM-guard/proxy/internal/rules/engine.go`)
- Jailbreak service client → Firewall inspection API: requests inspection (evidence: `README.md`)
- Firewall inspection API → Jailbreak classifier: scores prompt (evidence: `LLM-guard/services/firewall/app.py`)
- Jailbreak classifier → Classifier training: loads model from (evidence: `LLM-guard/services/firewall/classifier.py`)
- Classifier training → Training data: loads examples (evidence: `LLM-guard/services/firewall/train.py`)
- Classifier training → Text preprocessing: uses preprocessing (evidence: `LLM-guard/services/firewall/train.py`)
- Prompt rules → DLP service client: passes prompt (evidence: `README.md`)
- DLP service client → DLP redact and restore API: redacts and restores (evidence: `README.md`)
- DLP redact and restore API → PII analyzer: analyzes text (evidence: `LLM-guard/dlp-service/app.py`)
- PII analyzer → API key recognizers: registers recognizer (evidence: `LLM-guard/dlp-service/analyzer.py`)
- DLP service client → Prompt hardening: returns masked prompt (evidence: `README.md`)
- Prompt hardening → Language model: forwards prompt (evidence: `README.md`)
- Language model → Output validation: returns output (evidence: `README.md`)
- Output validation → DLP service client: requests restoration (evidence: `README.md`)
- Output validation → Client response: returns validated output (evidence: `README.md`)
- Proxy server → Audit telemetry: reports decisions (evidence: `README.md`)
- Audit telemetry → Analytics API and store: forwards audit events (evidence: `README.md`)
- Analytics API and store → Security dashboard: serves dashboard (evidence: `LLM-guard/sidecar/analytics/app.py`)
