# role-confusion/prompt-injection-as-role-confusion architecture

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

- Interactive diagram: https://gitdiagram.com/role-confusion/prompt-injection-as-role-confusion
- Repository: https://github.com/role-confusion/prompt-injection-as-role-confusion

## Overview

This is a research-reproduction repository for studying prompt injection as role confusion, rather than a deployed application. Its main workflow generates or collects conversations and attack examples, evaluates CoT-forgery attacks, exports model activations, and uses role probes to analyze those activations; separate notebooks reproduce plots and results. The README documents these experiment-stage relationships, but the notebook source was not sampled, so the graph does not infer their internal calls. Utility nodes preserve the central indexed runtime modules and sampled model-forward helpers.

Main entry points: [`experiments/role-analysis`](https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/role-analysis) (Train role probes), [`experiments/cot-forgery-chat-evals`](https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/cot-forgery-chat-evals) (Chat generations), [`experiments/cot-forgery-agent-evals`](https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/cot-forgery-agent-evals) (Agent evaluations), [`experiments/cot-forgery-role-confusion`](https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/cot-forgery-role-confusion) (Injection analyses)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_role_space["Role-space analysis"]
  node_conversation_data["Conversation data"]
  node_role_probe_training["Train role probes"]
  node_role_space_plots["Role-space plots"]
end

subgraph group_attacks["CoT-forgery evaluations"]
  node_chat_forgery["Generate chat forgeries"]
  node_chat_generations["Chat generations"]
  node_chat_results["Chat attack results"]
  node_agent_evaluations["Agent evaluations"]
  node_agent_results["Agent results"]
end

subgraph group_confusion["Role-confusion analysis"]
  node_chat_activations["Chat activations"]
  node_agent_activations["Agent activations"]
  node_standard_injections["Standard injections"]
  node_injection_analysis["Injection analyses"]
end

subgraph group_runtime["Model and data utilities"]
  node_dataset["Token dataset<br/>[dataset.py]"]
  node_probes["Probe operations<br/>[probes.py]"]
  node_role_assignments["Token role labels"]
  node_store_outputs["Output conversion<br/>[store_outputs.py]"]
  node_openrouter["OpenRouter requests<br/>[openrouter.py]"]
  node_model_helpers["Model forward helpers"]
  node_glm_forward["GLM MoE forward<br/>[glm4moe.py]"]
end

subgraph group_formatting["Role formatting"]
  node_role_templates["Role templates<br/>[role_templates.py]"]
  node_harmony["Harmony parsing<br/>[harmony.py]"]
end

node_researcher(("Researcher"))

node_researcher -->|"starts analysis"| node_conversation_data
node_conversation_data -->|"provides conversations"| node_role_probe_training
node_role_probe_training -->|"provides projections"| node_role_space_plots
node_researcher -->|"starts evaluation"| node_chat_forgery
node_chat_forgery -->|"supplies prompts"| node_chat_generations
node_chat_generations -->|"feeds classification"| node_chat_results
node_researcher -->|"starts evaluation"| node_agent_evaluations
node_agent_evaluations -->|"produces outputs"| node_agent_results
node_chat_generations -->|"provides inputs"| node_chat_activations
node_agent_evaluations -->|"provides inputs"| node_agent_activations
node_role_probe_training -->|"provides probes"| node_injection_analysis
node_chat_activations -->|"provides activations"| node_injection_analysis
node_agent_activations -->|"provides activations"| node_injection_analysis
node_researcher -->|"starts experiments"| node_standard_injections
node_glm_forward -->|"uses helpers"| node_model_helpers

click node_conversation_data "https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/role-analysis"
click node_role_probe_training "https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/role-analysis"
click node_role_space_plots "https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/role-analysis"
click node_chat_forgery "https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/cot-forgery-chat-evals"
click node_chat_generations "https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/cot-forgery-chat-evals"
click node_chat_results "https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/cot-forgery-chat-evals"
click node_agent_evaluations "https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/cot-forgery-agent-evals"
click node_agent_results "https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/cot-forgery-agent-evals"
click node_chat_activations "https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/cot-forgery-role-confusion"
click node_agent_activations "https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/cot-forgery-role-confusion"
click node_standard_injections "https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/agent-injections"
click node_injection_analysis "https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/cot-forgery-role-confusion"
click node_dataset "https://github.com/role-confusion/prompt-injection-as-role-confusion/blob/master/utils/dataset.py"
click node_probes "https://github.com/role-confusion/prompt-injection-as-role-confusion/blob/master/utils/probes.py"
click node_role_assignments "https://github.com/role-confusion/prompt-injection-as-role-confusion/blob/master/utils/role_assignments.py"
click node_store_outputs "https://github.com/role-confusion/prompt-injection-as-role-confusion/blob/master/utils/store_outputs.py"
click node_openrouter "https://github.com/role-confusion/prompt-injection-as-role-confusion/blob/master/utils/openrouter.py"
click node_model_helpers "https://github.com/role-confusion/prompt-injection-as-role-confusion/blob/master/utils/pretrained_models/_pretrained_helpers.py"
click node_glm_forward "https://github.com/role-confusion/prompt-injection-as-role-confusion/blob/master/utils/pretrained_models/glm4moe.py"
click node_role_templates "https://github.com/role-confusion/prompt-injection-as-role-confusion/blob/master/utils/role_templates.py"
click node_harmony "https://github.com/role-confusion/prompt-injection-as-role-confusion/blob/master/utils/harmony.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_conversation_data,node_role_probe_training,node_role_space_plots toneBlue
class node_chat_forgery,node_chat_generations,node_chat_results,node_agent_evaluations,node_agent_results toneAmber
class node_chat_activations,node_agent_activations,node_standard_injections,node_injection_analysis toneMint
class node_dataset,node_probes,node_role_assignments,node_store_outputs,node_openrouter,node_model_helpers,node_glm_forward toneRose
class node_role_templates,node_harmony,node_researcher toneIndigo
```

## Components

### Role-space analysis

- [Conversation data](https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/role-analysis): `experiments/role-analysis`
- [Train role probes](https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/role-analysis): `experiments/role-analysis`
- [Role-space plots](https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/role-analysis): `experiments/role-analysis`

### CoT-forgery evaluations

- [Generate chat forgeries](https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/cot-forgery-chat-evals): `experiments/cot-forgery-chat-evals`
- [Chat generations](https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/cot-forgery-chat-evals): `experiments/cot-forgery-chat-evals`
- [Chat attack results](https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/cot-forgery-chat-evals): `experiments/cot-forgery-chat-evals`
- [Agent evaluations](https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/cot-forgery-agent-evals): `experiments/cot-forgery-agent-evals`
- [Agent results](https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/cot-forgery-agent-evals): `experiments/cot-forgery-agent-evals`

### Role-confusion analysis

- [Chat activations](https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/cot-forgery-role-confusion): `experiments/cot-forgery-role-confusion`
- [Agent activations](https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/cot-forgery-role-confusion): `experiments/cot-forgery-role-confusion`
- [Standard injections](https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/agent-injections): `experiments/agent-injections`
- [Injection analyses](https://github.com/role-confusion/prompt-injection-as-role-confusion/tree/master/experiments/cot-forgery-role-confusion): `experiments/cot-forgery-role-confusion`

### Model and data utilities

- [Token dataset](https://github.com/role-confusion/prompt-injection-as-role-confusion/blob/master/utils/dataset.py): `utils/dataset.py`
- [Probe operations](https://github.com/role-confusion/prompt-injection-as-role-confusion/blob/master/utils/probes.py): `utils/probes.py`
- [Token role labels](https://github.com/role-confusion/prompt-injection-as-role-confusion/blob/master/utils/role_assignments.py): `utils/role_assignments.py`
- [Output conversion](https://github.com/role-confusion/prompt-injection-as-role-confusion/blob/master/utils/store_outputs.py): `utils/store_outputs.py`
- [OpenRouter requests](https://github.com/role-confusion/prompt-injection-as-role-confusion/blob/master/utils/openrouter.py): `utils/openrouter.py`
- [Model forward helpers](https://github.com/role-confusion/prompt-injection-as-role-confusion/blob/master/utils/pretrained_models/_pretrained_helpers.py): `utils/pretrained_models/_pretrained_helpers.py`
- [GLM MoE forward](https://github.com/role-confusion/prompt-injection-as-role-confusion/blob/master/utils/pretrained_models/glm4moe.py): `utils/pretrained_models/glm4moe.py`

### Role formatting

- [Role templates](https://github.com/role-confusion/prompt-injection-as-role-confusion/blob/master/utils/role_templates.py): `utils/role_templates.py`
- [Harmony parsing](https://github.com/role-confusion/prompt-injection-as-role-confusion/blob/master/utils/harmony.py): `utils/harmony.py`

### Other components

- **Researcher**

## Connections

- Researcher → Conversation data: starts analysis (evidence: `README.md`)
- Conversation data → Train role probes: provides conversations (evidence: `README.md`)
- Train role probes → Role-space plots: provides projections (evidence: `README.md`)
- Researcher → Generate chat forgeries: starts evaluation (evidence: `README.md`)
- Generate chat forgeries → Chat generations: supplies prompts (evidence: `README.md`)
- Chat generations → Chat attack results: feeds classification (evidence: `README.md`)
- Researcher → Agent evaluations: starts evaluation (evidence: `README.md`)
- Agent evaluations → Agent results: produces outputs (evidence: `README.md`)
- Chat generations → Chat activations: provides inputs (evidence: `README.md`)
- Agent evaluations → Agent activations: provides inputs (evidence: `README.md`)
- Train role probes → Injection analyses: provides probes (evidence: `README.md`)
- Chat activations → Injection analyses: provides activations (evidence: `README.md`)
- Agent activations → Injection analyses: provides activations (evidence: `README.md`)
- Researcher → Standard injections: starts experiments (evidence: `README.md`)
- GLM MoE forward → Model forward helpers: uses helpers (evidence: `utils/pretrained_models/glm4moe.py`)
