# Llama Guard

[Llama](https://www.edgepedia.org/zh/llama-model-family) Guard 是 Meta 推出的一系列开放权重安全分类器，每一个都通过微调 Llama 大语言模型构建，用于将 AI 提示和响应标注为安全或不安全，并在不安全时给出危害类别。首个版本于 2023 年 12 月作为 Meta 的 Purple Llama 信任与安全项目的一部分发布，该系列此后已从 7B 纯文本分类器发展为可同时检查文本和图像的 12B 多模态模型。<sup>[1](https://arxiv.org/html/2312.06674v1/)</sup><sup> • </sup><sup>[2](https://ai.meta.com/blog/purple-llama-open-trust-safety-generative-ai/)</sup>

关于证据的说明：本文所涵盖的公开记录中的所有来源均由 Meta 自己发布，包括原始论文、模型卡和产品公告。

| 事实 | 详情 |
|---|---|
| 首次发布 | Llama Guard 7B，2023 年 12 月，由 Llama 2-7B 微调<sup>[1](https://arxiv.org/html/2312.06674v1/)</sup> |
| 最新版本 | Llama Guard 4 12B，多模态，由 Llama 4 Scout 剪枝而来，2025 年 4 月<sup>[3](https://github.com/meta-llama/PurpleLlama/blob/main/Llama-Guard4/12B/MODEL%5FCARD.md)</sup> |
| 已发布规模 | 7B、8B、1B、1B-INT4（440MB）、11B-vision、12B<sup>[1](https://arxiv.org/html/2312.06674v1/)</sup><sup> • </sup><sup>[4](https://ai.meta.com/research/publications/llama-guard-3-1b-int4-compact-and-efficient-safeguard-for-human-ai-conversations/)</sup><sup> • </sup><sup>[3](https://github.com/meta-llama/PurpleLlama/blob/main/Llama-Guard4/12B/MODEL%5FCARD.md)</sup> |
| 危害分类体系 | MLCommons 标准危害分类体系（13 类危害），自 Llama Guard 3 起<sup>[5](https://github.com/meta-llama/PurpleLlama/tree/8c5a89e7e443d5d76fa30f27320280d230e88e88)</sup> |
| 厂商报告的 F1（v1，Meta 测试集） | 提示 0.945 / 响应 0.953，对比 OpenAI 审核 API 的 0.764 / 0.769<sup>[1](https://arxiv.org/html/2312.06674v1/)</sup> |
| 部署 | 开放权重供自托管；Llama Guard 4 可在单 GPU 上运行；各基础模型适用相应的 Llama 社区许可证<sup>[6](https://developer.meta.com/ai/docs/model-cards-and-prompt-formats/llama-guard-4/)</sup><sup> • </sup><sup>[5](https://github.com/meta-llama/PurpleLlama/tree/8c5a89e7e443d5d76fa30f27320280d230e88e88)</sup> |
| 已承认的局限 | 易受提示注入影响、对良性提示过度拦截、需要最新事实知识的类别<sup>[1](https://arxiv.org/html/2312.06674v1/)</sup><sup> • </sup><sup>[3](https://github.com/meta-llama/PurpleLlama/blob/main/Llama-Guard4/12B/MODEL%5FCARD.md)</sup> |

## Llama Guard 是什么

Llama Guard 不是一个小型专用分类器，而是一个被改作分类器的完整 LLM。Meta 微调一个 Llama 基础模型，使得在给定一个包含策略（危害分类体系）和待判断对话的、经过精心格式化的提示时，模型输出单个标签 `safe` 或 `unsafe`，并在不安全时输出危害类别。同一个模型同时处理两个方向：生成前的提示分类，以及生成后的响应分类。<sup>[1](https://arxiv.org/html/2312.06674v1/)</sup><sup> • </sup><sup>[7](https://raw.githubusercontent.com/meta-llama/PurpleLlama/main/Llama-Guard/MODEL_CARD.md)</sup>

Meta 为首个版本选择 [Llama 2](https://www.edgepedia.org/zh/llama-2)-7B，即 Llama 2 三种规模中最小的一个，以降低推理与部署成本，并公开发布权重，使从业者不必依赖处理能力有限的付费审核 API。<sup>[1](https://arxiv.org/html/2312.06674v1/)</sup> 在 Purple Llama 中，Llama Guard 与 Prompt Guard（提示注入分类器）和 Code Shield（不安全代码检测）并列，构成 Meta 为基于 Llama 的系统提供的参考防护措施。<sup>[5](https://github.com/meta-llama/PurpleLlama/tree/8c5a89e7e443d5d76fa30f27320280d230e88e88)</sup>

## 版本与发布时间线

**Llama Guard（7B，2023 年 12 月）。** 原始模型，由 Llama 2-7B 微调而来，随 Purple Llama 一同发布，Meta 称其可公开获取，并在常见公开基准上具有竞争力。<sup>[2](https://ai.meta.com/blog/purple-llama-open-trust-safety-generative-ai/)</sup><sup> • </sup><sup>[7](https://raw.githubusercontent.com/meta-llama/PurpleLlama/main/Llama-Guard/MODEL_CARD.md)</sup>

**Llama Guard 2（8B，2024 年）。** 基于 Llama 3 重建，具有相同的提示/响应双重分类角色和 safe/unsafe 输出格式。<sup>[8](https://github.com/meta-llama/PurpleLlama/blob/main/Llama-Guard2/MODEL_CARD.md)</sup>

**Llama Guard 3（2024 年）。** 基于 Llama 3.1 和 3.2 模型微调，并针对 [MLCommons](https://www.edgepedia.org/zh/mlcommons) 标准危害分类体系优化。3 系列新增对七种额外语言的支持、128k token 上下文窗口、图像推理，以及对为网络攻击提供帮助的响应和恶意代码输出的检测。它以 8B、1B 和 11B-vision 规模发布，采用 Llama 3.2 社区许可证。<sup>[9](https://github.com/meta-llama/PurpleLlama/blob/main/Llama-Guard3/8B/MODEL%5FCARD.md)</sup><sup> • </sup><sup>[5](https://github.com/meta-llama/PurpleLlama/tree/8c5a89e7e443d5d76fa30f27320280d230e88e88)</sup>

**Llama Guard 3 Vision（2024 年 11 月）。** 首个多模态 Llama Guard，基于 Llama 3.2-Vision 微调，用于依据 MLCommons 分类体系的 13 类危害，对有害的文本加图像提示和文本响应进行分类。<sup>[10](https://arxiv.org/html/2411.10414v1)</sup>

**Llama Guard 3-1B-INT4（Meta Connect，2024 年末）。** 一个量化后的 440MB 版本，体积约为 Llama Guard 3-1B 的七分之一，面向端侧使用。<sup>[4](https://ai.meta.com/research/publications/llama-guard-3-1b-int4-compact-and-efficient-safeguard-for-human-ai-conversations/)</sup>

**Llama Guard 4（12B，2025 年 4 月）。** 一个原生多模态分类器，结合了 Llama Guard 3-8B 与 3-11B-vision 的能力。Meta 将 [Llama 4](https://www.edgepedia.org/zh/llama-4) Scout 混合专家预训练模型剪枝为稠密早期融合架构，未进行额外预训练，而是依赖 Llama 4 的现有能力；该模型与 Llama 4 共享分词器和视觉编码器，并可在单 GPU 上运行。它与 Llama API（有限预览）一同推出，并集成到 Llama Moderations API 中。<sup>[3](https://github.com/meta-llama/PurpleLlama/blob/main/Llama-Guard4/12B/MODEL%5FCARD.md)</sup><sup> • </sup><sup>[6](https://developer.meta.com/ai/docs/model-cards-and-prompt-formats/llama-guard-4/)</sup><sup> • </sup><sup>[11](https://ai.meta.com/blog/ai-defenders-program-llama-protection-tools/)</sup>

本记录没有 2025 年 4 月之后的来源，因此此后任何发布或事件均未涵盖。

## 工作原理

其机制是由提示格式驱动的分类。开发者将危害分类体系作为输入提示的一部分提供，从而使策略可配置。<sup>[1](https://arxiv.org/html/2312.06674v1/)</sup> 从 Llama Guard 3 起，默认分类体系是 MLCommons 标准危害分类体系，这是一套跨行业的 13 类危害分类；模型还经过额外调优，以捕捉托管 LLM 可能输出、供代码解释器执行的、为网络攻击提供帮助的响应和恶意代码。<sup>[5](https://github.com/meta-llama/PurpleLlama/tree/8c5a89e7e443d5d76fa30f27320280d230e88e88)</sup>

以基础模型的标准衡量，最初的训练规模不大：单台机器配备 8 块 A100 80GB GPU，批大小为 2，序列长度为 4096，学习率为 2×10⁻⁶，训练 500 步，约相当于在整个训练集上训练一轮。<sup>[1](https://arxiv.org/html/2312.06674v1/)</sup> 对于 Llama Guard 4，Meta 将纯文本和多模态训练数据按约 3:1 的比例混合，其中包括多图样本（测试样本大多包含两到五张图像），以及由专家人工标注员撰写或从英文翻译而来的多语言数据。<sup>[3](https://github.com/meta-llama/PurpleLlama/blob/main/Llama-Guard4/12B/MODEL%5FCARD.md)</sup>

多模态变体改变了威胁面。在 Meta 自己的白盒对抗测试中，Llama Guard 3 Vision 在分类响应方面比分类提示更稳健，因为它主要依赖模型响应，用 Meta 的话说，它实际上忽略了基于提示的攻击。<sup>[10](https://arxiv.org/html/2411.10414v1)</sup>

## 基准表现：仅有厂商报告

本节所有性能数据均来自 Meta 的论文和模型卡；本记录中没有独立评估。

在 2023 年 12 月的论文中，Meta 报告了其自有测试集上的 F1 分数：提示分类为 0.945，响应分类为 0.953；OpenAI 的审核 API 分别为 0.764 和 0.769，[Perspective API](https://www.edgepedia.org/zh/perspective-api) 分别为 0.728 和 0.699。在 OpenAI 自己的审核测试集上，排名发生反转：OpenAI 的 API 得分为 0.856，Llama Guard 为 0.847。在 ToxicChat 基准上，Meta 报告 Llama Guard 为 0.626，而 [OpenAI API](https://www.edgepedia.org/zh/openai-api) 为 0.588。<sup>[1](https://arxiv.org/html/2312.06674v1/)</sup> 这里正是论文自身数字与 Meta 博客表述出现分歧的地方：博客公告将 Llama Guard 呈现为在常见基准上具有竞争力，而论文显示 OpenAI 的 API 在 OpenAI 的测试集上略占优势。<sup>[2](https://ai.meta.com/blog/purple-llama-open-trust-safety-generative-ai/)</sup>

对于 Llama Guard 3-8B，Meta 的模型卡称其相较 Llama Guard 2 有所改进，并在英语、多语言和工具使用安全分类上优于 GPT-4，且假阳性率低得多；在 [XSTest](https://www.edgepedia.org/zh/xstest) 过度拒答基准上，其 F1 与 Llama Guard 2 相当，假阳性率更低。<sup>[9](https://github.com/meta-llama/PurpleLlama/blob/main/Llama-Guard3/8B/MODEL%5FCARD.md)</sup> 对于 Llama Guard 4，Meta 报告称，在内部测试集上，它在英语和多语言文本以及单图和多图提示的输入与输出过滤方面，大致达到或超过 Llama Guard 3-8B 与 3-11B-vision。<sup>[3](https://github.com/meta-llama/PurpleLlama/blob/main/Llama-Guard4/12B/MODEL%5FCARD.md)</sup>

由于每项比较都使用 Meta 自己的测试集，而且所有评估均由 Meta 进行，这些数字只能说明 Meta 测到了什么，而不能说明第三方验证了什么。

## 关键数字

- **规模：** 7B（v1）、8B（v2 和 3-8B）、1B 和 1B-INT4（440MB，约为 3-1B 的七分之一）、11B-vision、12B（Guard 4）。<sup>[1](https://arxiv.org/html/2312.06674v1/)</sup><sup> • </sup><sup>[4](https://ai.meta.com/research/publications/llama-guard-3-1b-int4-compact-and-efficient-safeguard-for-human-ai-conversations/)</sup><sup> • </sup><sup>[3](https://github.com/meta-llama/PurpleLlama/blob/main/Llama-Guard4/12B/MODEL%5FCARD.md)</sup>
- **上下文：** Llama Guard 3 系列为 128k token 窗口。<sup>[5](https://github.com/meta-llama/PurpleLlama/tree/8c5a89e7e443d5d76fa30f27320280d230e88e88)</sup>
- **端侧吞吐（厂商报告）：** Llama Guard 3-1B-INT4 在普通 Android 移动 CPU 上达到至少每秒 30 个 token，首 token 时间不超过 2.5 秒，审核分数与 Llama Guard 3-1B 相当或更优。<sup>[4](https://ai.meta.com/research/publications/llama-guard-3-1b-int4-compact-and-efficient-safeguard-for-human-ai-conversations/)</sup>
- **硬件：** Llama Guard 4 可在单 GPU 上运行。<sup>[6](https://developer.meta.com/ai/docs/model-cards-and-prompt-formats/llama-guard-4/)</sup>
- **v1 F1 对比（Meta 测试集）：** Llama Guard 0.945/0.953；OpenAI 审核 API 0.764/0.769；Perspective API 0.728/0.699（提示/响应）。<sup>[1](https://arxiv.org/html/2312.06674v1/)</sup>

## 许可与获取方式

每个版本继承其基础模型的社区许可证：Llama Guard 采用 Llama 2 社区许可证，Llama Guard 2 采用 Llama 3 社区许可证，Llama Guard 3 系列模型采用 Llama 3.2 社区许可证。Purple Llama 仓库的评估与基准采用 MIT 许可证，而模型本身使用相应的 Llama 社区许可证。<sup>[5](https://github.com/meta-llama/PurpleLlama/tree/8c5a89e7e443d5d76fa30f27320280d230e88e88)</sup> 权重可下载用于自托管和微调，这是最初版本的明确设计目标。<sup>[1](https://arxiv.org/html/2312.06674v1/)</sup> 自 2025 年 4 月起，Llama Guard 4 还可通过 Meta 的 Llama API 以有限预览方式获取，并集成到 Llama Moderations API 中。<sup>[11](https://ai.meta.com/blog/ai-defenders-program-llama-protection-tools/)</sup>

本记录没有关于托管定价、或哪些推理提供商和框架已将 Llama Guard 采纳为默认防护栏的来源，因此无法在此记录其采用范围。

## References

1. [Llama Guard: LLM-based Input-Output Safeguard for Human-AI Conversations](https://arxiv.org/html/2312.06674v1/)
2. [Announcing Purple Llama: Towards open trust and safety in the new world of generative AI](https://ai.meta.com/blog/purple-llama-open-trust-safety-generative-ai/)
3. [Llama Guard 4 12B Model Card (meta-llama/PurpleLlama)](https://github.com/meta-llama/PurpleLlama/blob/main/Llama-Guard4/12B/MODEL%5FCARD.md)
4. [Llama Guard 3-1B-INT4: Compact and Efficient Safeguard for Human-AI Conversations](https://ai.meta.com/research/publications/llama-guard-3-1b-int4-compact-and-efficient-safeguard-for-human-ai-conversations/)
5. [meta-llama/PurpleLlama repository](https://github.com/meta-llama/PurpleLlama/tree/8c5a89e7e443d5d76fa30f27320280d230e88e88)
6. [Llama Guard 4 | Model Cards and Prompt formats (Meta developer docs)](https://developer.meta.com/ai/docs/model-cards-and-prompt-formats/llama-guard-4/)
7. [Llama Guard (v1) Model Card](https://raw.githubusercontent.com/meta-llama/PurpleLlama/main/Llama-Guard/MODEL_CARD.md)
8. [Llama Guard 2 Model Card](https://github.com/meta-llama/PurpleLlama/blob/main/Llama-Guard2/MODEL_CARD.md)
9. [Llama Guard 3-8B Model Card](https://github.com/meta-llama/PurpleLlama/blob/main/Llama-Guard3/8B/MODEL%5FCARD.md)
10. [Llama Guard 3 Vision: Safeguarding Human-AI Image Understanding Conversations](https://arxiv.org/html/2411.10414v1)
11. [Sharing new open source protection tools and advancements in AI privacy and security (Meta AI blog, April 2025)](https://ai.meta.com/blog/ai-defenders-program-llama-protection-tools/)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 19, 2026 · Edited: Sep 19, 2026; Oct 11, 2026 · Last review: Sep 19, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 现代人工智能：基础模型、生成式人工智能与人工智能产业 › Foundation-model methods and training › Safety methods, interpretability, and red-teaming

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/llama-guard

English original: https://www.edgepedia.org/llama-guard
