How meta-llama/purplellama works
Project Type and Purpose
• This repository is a monorepo of multiple security-focused tools and libraries rather than a single end-to-end application.
• Top-level components include:
• CodeShield: a Python library/CLI for detecting insecure code patterns.
• CybersecurityBenchmarks: a benchmarking framework and website for LLM security use cases.
• Llama-Guard / Prompt-Guard: collections of model cards and policies.
• LlamaFirewall: a Python library/CLI with pluggable scanners and a documentation website.
• SensitiveDocClassification: a Python service/CLI for classifying documents in Google Drive via an LLM and SQLite.
File Structure
• Each tool follows a consistent structure:
• src or top-level module folder containing main library code.
• CLI entry points under cli/ or scripts.
• Configuration or rules (e.g., YAML/JSON under rules/ or content_categories/).
• Tests under tests/.
• Documentation websites under website/ for CybersecurityBenchmarks and LlamaFirewall.
• Common cross-cutting elements: LLM clients/interfaces, rule engines, pattern-based analyzers, benchmark runners, Dockerfiles or workflows for CI/CD.
Main Components and Their Interactions
A. CodeShield Subsystem
• Core Library (codeshield.py, insecure_code_detector/)
• Rule Engine (regex / Semgrep rules under rules/)
• Analyzers & Issue Generators
• Example / CLI (example.py)
• Tests
• External Dependencies: GitHub / OSS APIs (for vulnerability data)
B. CybersecurityBenchmarks Subsystem
• Benchmark Core (benchmark/benchmark_utils.py, run.py)
• Autopatch Module (patch_generator, llm_interface)
• Datasets (JSON, generators)
• Infrastructure Scripts (Dockerfiles, CI scripts)
• Website (Docusaurus site under website/)
• External Services: LLM providers via llm.py
C. LlamaFirewall Subsystem
• CLI & Configuration (cli/, config.py)
• Core Firewall Engine (llamafirewall.py)
• Scanners (code_shield_scanner, prompt_guard_scanner, etc.)
• LLM Adapter (utils/base_llm.py)
• Examples & Notebooks
• Website Documentation
D. SensitiveDocClassification Subsystem
• CLI (cli/argument_parser.py)
• Core Classifier (classifyit/classifier.py)
• Google Drive Client (google_drive_client/drive_client.py)
• LLM Client (llm_client/llm_client.py)
• Local Database (SQLite via database/database.py)
• Content Categories (YAML config for PII detection)
• Tests
Architectural Patterns & Design Principles
• Modular “library + CLI + tests” structure for each tool.
• Rule-based engines for code and content scanning.
• Pluggable adapters/injectors for LLM services.
• Separation of concerns: scanning logic, configuration/rules, I/O layers (CLI, network, DB), and tests.
• Static site generation (Docusaurus) for documentation.