# saberfazliahmadi/eu-trustworthy-llm-stack architecture

> Architecture diagram of the GitHub repository saberfazliahmadi/eu-trustworthy-llm-stack, 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/saberfazliahmadi/eu-trustworthy-llm-stack
- Repository: https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack

## Overview

ExampleHR Assistant is an educational HR-policy and careers assistant, paired with a trust-and-audit toolkit. Its user workflow enters through the chat API, passes through the five-layer safety stack, uses policy-document retrieval for grounded generation, then verifies supported facts and returns citations and safety trace. The repository also provides provider adapters and separate evaluation, fairness, robustness, and red-team audits. Edges reflect the shown API and module references or README descriptions; unsampled subsystem details and unshown calls are intentionally left unconnected.

Main entry points: [`src/trust_llm/audits.py`](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/audits.py) (Audit orchestration), [`src/trust_llm/api/app.py`](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/api/app.py) (Chat API), [`src/trust_llm/rag/pipeline.py`](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/rag/pipeline.py) (Grounded RAG), [`src/trust_llm/guardrails/safety_stack.py`](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/guardrails/safety_stack.py) (Safety stack)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_chat["Assistant workflow"]
  node_api["Chat API<br/>[app.py]"]
end

subgraph group_model["Model and retrieval"]
  node_rag["Grounded RAG<br/>[pipeline.py]"]
  node_hrdocs["HR policy documents"]
  node_verifier["Fact verifier<br/>[fact_verifier.py]"]
  node_provider["Provider interfaces<br/>[base.py]"]
  node_mock["Mock provider<br/>[mock_provider.py]"]
  node_live["Live providers<br/>[live_provider.py]"]
end

subgraph group_trust["Safety controls"]
  node_stack["Safety stack<br/>[safety_stack.py]"]
  node_policy["Policy engine<br/>[engine.py]"]
  node_rules["Policy rules<br/>[policies.yaml]"]
end

subgraph group_audits["Trust audits"]
  node_ragdiag["RAG diagnostics<br/>[diagnostics.py]"]
  node_audits["Audit orchestration<br/>[audits.py]"]
  node_judge["LLM judge<br/>[llm_judge.py]"]
  node_metrics["Evaluation metrics<br/>[metrics.py]"]
  node_decoding["Decoding benchmarks<br/>[decoding_bench.py]"]
  node_counterfactuals["Counterfactual fairness<br/>[counterfactuals.py]"]
  node_reweighting["Loss reweighting"]
  node_subgroup["Subgroup audit<br/>[subgroup_audit.py]"]
  node_weat["WEAT analysis<br/>[weat.py]"]
  node_perturb["Input perturbations<br/>[perturbations.py]"]
  node_invariance["Invariance tests<br/>[invariance.py]"]
  node_redteam["Red-team runner<br/>[red_team_runner.py]"]
  node_scorecard["Security scorecard<br/>[scorecard.py]"]
  node_reports["Audit reports<br/>[reporting.py]"]
end

subgraph group_runtime["Runtime configuration"]
  node_config["Settings and factories<br/>[config.py]"]
  node_textutils["Text utilities<br/>[text_utils.py]"]
  node_cli["CLI entry point<br/>[cli.py]"]
end

node_user(("User / applicant"))

node_user -->|"sends request"| node_api
node_api -->|"processes message"| node_stack
node_api -->|"scores facts"| node_verifier
node_api -->|"returns response"| node_user
node_stack -->|"evaluates rules"| node_policy
node_policy -->|"loads rules"| node_rules
node_stack -->|"grounds answers"| node_rag
node_hrdocs -->|"provides passages"| node_rag
node_rag -->|"generates answer"| node_provider
node_rag -->|"loads documents"| node_hrdocs
node_config -->|"selects provider"| node_mock
node_config -->|"selects provider"| node_live
node_audits -->|"runs diagnostics"| node_ragdiag
node_audits -->|"runs RAG audits"| node_rag
node_audits -->|"runs judging"| node_judge
node_audits -->|"computes metrics"| node_metrics
node_audits -->|"tests fairness"| node_counterfactuals
node_audits -->|"tests mitigation"| node_reweighting
node_audits -->|"runs subgroup audit"| node_subgroup
node_audits -->|"runs association test"| node_weat
node_audits -->|"tests robustness"| node_perturb
node_audits -->|"tests invariance"| node_invariance
node_audits -->|"runs attacks"| node_redteam
node_redteam -->|"scores outcomes"| node_scorecard
node_judge -->|"requests judgments"| node_provider
node_decoding -->|"uses metrics"| node_metrics
node_audits -->|"writes reports"| node_reports
node_cli -->|"runs audits"| node_audits
node_cli -->|"serves API"| node_api
node_verifier -->|"uses text helpers"| node_textutils

click node_api "https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/api/app.py"
click node_stack "https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/guardrails/safety_stack.py"
click node_policy "https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/guardrails/engine.py"
click node_rules "https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/guardrails/policies.yaml"
click node_rag "https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/rag/pipeline.py"
click node_hrdocs "https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/tree/main/data/hr_policies"
click node_verifier "https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/rag/fact_verifier.py"
click node_ragdiag "https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/rag/diagnostics.py"
click node_provider "https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/providers/base.py"
click node_mock "https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/providers/mock_provider.py"
click node_live "https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/providers/live_provider.py"
click node_config "https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/config.py"
click node_audits "https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/audits.py"
click node_judge "https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/evaluation/llm_judge.py"
click node_metrics "https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/evaluation/metrics.py"
click node_decoding "https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/evaluation/decoding_bench.py"
click node_counterfactuals "https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/fairness/counterfactuals.py"
click node_reweighting "https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/fairness/loss_reweighting.py"
click node_subgroup "https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/fairness/subgroup_audit.py"
click node_weat "https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/fairness/weat.py"
click node_perturb "https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/robustness/perturbations.py"
click node_invariance "https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/robustness/invariance.py"
click node_redteam "https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/security/red_team_runner.py"
click node_scorecard "https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/security/scorecard.py"
click node_textutils "https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/text_utils.py"
click node_cli "https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/cli.py"
click node_reports "https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/reporting.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_api,node_user toneBlue
class node_rag,node_hrdocs,node_verifier,node_provider,node_mock,node_live toneAmber
class node_stack,node_policy,node_rules toneMint
class node_ragdiag,node_audits,node_judge,node_metrics,node_decoding,node_counterfactuals,node_reweighting,node_subgroup,node_weat,node_perturb,node_invariance,node_redteam,node_scorecard,node_reports toneRose
class node_config,node_textutils,node_cli toneIndigo
```

## Components

### Assistant workflow

- [Chat API](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/api/app.py): `src/trust_llm/api/app.py`

### Model and retrieval

- [Grounded RAG](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/rag/pipeline.py): `src/trust_llm/rag/pipeline.py`
- [HR policy documents](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/tree/main/data/hr_policies): `data/hr_policies`
- [Fact verifier](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/rag/fact_verifier.py): `src/trust_llm/rag/fact_verifier.py`
- [Provider interfaces](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/providers/base.py): `src/trust_llm/providers/base.py`
- [Mock provider](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/providers/mock_provider.py): `src/trust_llm/providers/mock_provider.py`
- [Live providers](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/providers/live_provider.py): `src/trust_llm/providers/live_provider.py`

### Safety controls

- [Safety stack](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/guardrails/safety_stack.py): `src/trust_llm/guardrails/safety_stack.py`
- [Policy engine](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/guardrails/engine.py): `src/trust_llm/guardrails/engine.py`
- [Policy rules](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/guardrails/policies.yaml): `src/trust_llm/guardrails/policies.yaml`

### Trust audits

- [RAG diagnostics](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/rag/diagnostics.py): `src/trust_llm/rag/diagnostics.py`
- [Audit orchestration](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/audits.py): `src/trust_llm/audits.py`
- [LLM judge](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/evaluation/llm_judge.py): `src/trust_llm/evaluation/llm_judge.py`
- [Evaluation metrics](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/evaluation/metrics.py): `src/trust_llm/evaluation/metrics.py`
- [Decoding benchmarks](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/evaluation/decoding_bench.py): `src/trust_llm/evaluation/decoding_bench.py`
- [Counterfactual fairness](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/fairness/counterfactuals.py): `src/trust_llm/fairness/counterfactuals.py`
- [Loss reweighting](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/fairness/loss_reweighting.py): `src/trust_llm/fairness/loss_reweighting.py`
- [Subgroup audit](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/fairness/subgroup_audit.py): `src/trust_llm/fairness/subgroup_audit.py`
- [WEAT analysis](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/fairness/weat.py): `src/trust_llm/fairness/weat.py`
- [Input perturbations](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/robustness/perturbations.py): `src/trust_llm/robustness/perturbations.py`
- [Invariance tests](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/robustness/invariance.py): `src/trust_llm/robustness/invariance.py`
- [Red-team runner](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/security/red_team_runner.py): `src/trust_llm/security/red_team_runner.py`
- [Security scorecard](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/security/scorecard.py): `src/trust_llm/security/scorecard.py`
- [Audit reports](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/reporting.py): `src/trust_llm/reporting.py`

### Runtime configuration

- [Settings and factories](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/config.py): `src/trust_llm/config.py`
- [Text utilities](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/text_utils.py): `src/trust_llm/text_utils.py`
- [CLI entry point](https://github.com/saberfazliahmadi/eu-trustworthy-llm-stack/blob/main/src/trust_llm/cli.py): `src/trust_llm/cli.py`

### Other components

- **User / applicant**

## Connections

- User / applicant → Chat API: sends request (evidence: `README.md`)
- Chat API → Safety stack: processes message (evidence: `src/trust_llm/api/app.py`)
- Chat API → Fact verifier: scores facts (evidence: `src/trust_llm/api/app.py`)
- Chat API → User / applicant: returns response (evidence: `README.md`)
- Safety stack → Policy engine: evaluates rules (evidence: `src/trust_llm/guardrails/safety_stack.py`)
- Policy engine → Policy rules: loads rules (evidence: `README.md`)
- Safety stack → Grounded RAG: grounds answers (evidence: `README.md`)
- HR policy documents → Grounded RAG: provides passages (evidence: `README.md`)
- Grounded RAG → Provider interfaces: generates answer (evidence: `src/trust_llm/rag/pipeline.py`)
- Grounded RAG → HR policy documents: loads documents (evidence: `src/trust_llm/rag/pipeline.py`)
- Settings and factories → Mock provider: selects provider (evidence: `src/trust_llm/config.py`)
- Settings and factories → Live providers: selects provider (evidence: `src/trust_llm/config.py`)
- Audit orchestration → RAG diagnostics: runs diagnostics (evidence: `src/trust_llm/audits.py`)
- Audit orchestration → Grounded RAG: runs RAG audits (evidence: `src/trust_llm/audits.py`)
- Audit orchestration → LLM judge: runs judging (evidence: `src/trust_llm/audits.py`)
- Audit orchestration → Evaluation metrics: computes metrics (evidence: `src/trust_llm/audits.py`)
- Audit orchestration → Counterfactual fairness: tests fairness (evidence: `src/trust_llm/audits.py`)
- Audit orchestration → Loss reweighting: tests mitigation (evidence: `src/trust_llm/audits.py`)
- Audit orchestration → Subgroup audit: runs subgroup audit (evidence: `src/trust_llm/audits.py`)
- Audit orchestration → WEAT analysis: runs association test (evidence: `src/trust_llm/audits.py`)
- Audit orchestration → Input perturbations: tests robustness (evidence: `src/trust_llm/audits.py`)
- Audit orchestration → Invariance tests: tests invariance (evidence: `src/trust_llm/audits.py`)
- Audit orchestration → Red-team runner: runs attacks (evidence: `src/trust_llm/audits.py`)
- Red-team runner → Security scorecard: scores outcomes (evidence: `src/trust_llm/security/red_team_runner.py`)
- LLM judge → Provider interfaces: requests judgments (evidence: `src/trust_llm/evaluation/llm_judge.py`)
- Decoding benchmarks → Evaluation metrics: uses metrics (evidence: `src/trust_llm/evaluation/decoding_bench.py`)
- Audit orchestration → Audit reports: writes reports (evidence: `src/trust_llm/audits.py`)
- CLI entry point → Audit orchestration: runs audits (evidence: `src/trust_llm/cli.py`)
- CLI entry point → Chat API: serves API (evidence: `src/trust_llm/cli.py`)
- Fact verifier → Text utilities: uses text helpers (evidence: `src/trust_llm/rag/fact_verifier.py`)
