█

AI/TLDR

Buy me a coffee
Buy me a coffee

PurpleLlama

Meta's open trust-and-safety tools and benchmarks for evaluating and guarding LLMs

Evaluation & Red-TeamingOpen source
Language
Python
License
MIT
$pip3 install codeshield
IN SHORT

What is PurpleLlama?

PurpleLlama is an umbrella project from Meta that gathers tools and evaluations for building responsibly with open generative AI models. The name comes from the cybersecurity idea of "purple teaming" — combining red-team (attack) and blue-team (defense) work — applied to LLM safety. It sits in the Evaluation & Red-Teaming category of the Evaluation & Production Ops tools and is open-source, written in Python and licensed MIT.

Overview

PurpleLlama is an umbrella project from Meta that gathers tools and evaluations for building responsibly with open generative AI models. The name comes from the cybersecurity idea of "purple teaming" — combining red-team (attack) and blue-team (defense) work — applied to LLM safety. Its first releases focus on cybersecurity benchmarks and input/output safeguards, with more planned over time.

It is aimed at developers and ML teams who run LLMs in production and need to filter inputs and outputs, score a model's security risk, or catch insecure generated code. The project bundles several components: Llama Guard for content moderation, Prompt Guard for detecting prompt injection and jailbreaks, Code Shield for filtering insecure code, and CyberSecEval as a cybersecurity benchmark suite.

As an eval-and-guardrail framework, PurpleLlama sits between your application and the model. The safeguard models classify or block risky content at inference time, while the benchmarks let you measure how a given model behaves before you ship it.

What it does

  • Llama Guard: input and output moderation models, fine-tuned from Llama 3.1/3.2, that detect content matching the MLCommons hazards taxonomy
  • Prompt Guard: a model that flags prompt injection and jailbreak attempts before they reach your LLM
  • Code Shield: inference-time filtering of insecure code generated by LLMs, with block/warn treatment recommendations
  • CyberSecEval: cybersecurity benchmarks for LLMs based on industry standards like CWE and MITRE ATT&CK
  • Permissive licensing: evals and benchmarks under MIT; safeguard models under the corresponding Llama Community License
  • Covers both attack and defense ("purple teaming") so you can evaluate risk and add guardrails from one project

Getting started

The components ship separately. Code Shield is available as a pip package; the Llama Guard and Prompt Guard models are downloaded from Hugging Face. Here is a minimal Code Shield example.

Install Code Shield

Install the codeshield package from PyPI.

bashbash
pip3 install codeshield

Scan LLM-generated code

Call CodeShield.scan_code on model output and act on the result's is_insecure flag and recommended_treatment.

pythonpython
from codeshield.cs import CodeShield

async def scan_llm_output(llm_output_code):
    result = await CodeShield.scan_code(llm_output_code)
    if result.is_insecure:
        if result.recommended_treatment == "block":
            llm_output_code = "*** Code Security issues found, blocking the code ***"
        if result.recommended_treatment == "warn":
            llm_output_code = (
                llm_output_code
                + "*** Warning: The generated snippit contains insecure code ***"
            )
    summary = "Security issue detected" if result.is_insecure else "No issues found"

Add the safeguard models

For moderation and prompt-attack detection, download the Llama Guard and Prompt Guard models from Hugging Face and run them around your LLM calls. See the project's Hugging Face page and the CodeShield usage notebook for full examples.

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

When to use it

  • Moderate user inputs and model outputs against a hazards taxonomy with Llama Guard before content reaches end users
  • Detect prompt injection and jailbreak attempts with Prompt Guard in an LLM-powered application
  • Filter insecure code suggestions from a coding assistant or code interpreter using Code Shield
  • Benchmark an LLM's cybersecurity risk with CyberSecEval before deploying it

How PurpleLlama compares

PurpleLlama alongside other open-source evaluation & red-teaming tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
Strix★ 78.4kStrix runs autonomous AI agents that act like hackers, dynamically running your code to find vulnerabilities and validate them with real proof-of-concepts.
iFixAi★ 47.6kAn agent auditor that runs up to 60 inspections across fabrication, manipulation, deception, unpredictability and opacity, and returns an A–F grade judged by a model from a different vendor.
promptfoo★ 27.9kA developer-first CLI and library for testing and comparing prompts and models, with red-teaming probes for prompt injection, PII leaks, and other vulnerabilities.
OpenAI Evals★ 19.8kA framework and open registry for building and running evaluations of LLMs and LLM-based systems, including prompt chains and tool-using agents.
DeepEval★ 19.7kAn open-source Python framework that tests LLM apps like unit tests, with 50+ metrics for RAG, agents, chatbots, and safety, and a Pytest integration for CI/CD.
Ragas★ 16.5kAn evaluation toolkit focused on retrieval-augmented generation that scores answer faithfulness, context precision/recall, and relevancy, often without needing ground-truth labels.
Arize Phoenix★ 12.5kAn open-source observability and evaluation tool for tracing LLM and agent behavior, running evals on traces, and troubleshooting issues in development and production.
PurpleLlama★ 4.5kMeta's open trust-and-safety tools and benchmarks for evaluating and guarding LLMs