# PyRIT

PyRIT（Python Risk Identification Toolkit for generative AI，生成式AI Python风险识别工具包）是微软发布的一个开源Python框架，用于对生成式AI系统（如大语言模型端点和Copilot式助手）进行自动化对抗测试，即红队测试。微软于2024年2月22日公开发布该框架，其基础是公司自2019年以来的内部红队测试投入，以及2022年开始对生成式AI系统进行红队测试时编写的一系列一次性脚本。<sup>[1](https://www.microsoft.com/en-us/security/blog/2024/02/22/announcing-microsofts-open-automation-framework-to-red-team-generative-ai-systems/)</sup> 该框架将AI红队测试工作中重复性的部分自动化：生成或获取恶意提示词、将其发送至目标模型、根据目标的回复调整后续提示词，以及评判回复是否违反了安全策略。微软明确表示，PyRIT并非人工红队测试的替代品，而是增强红队测试人员领域专业知识的工具。<sup>[1](https://www.microsoft.com/en-us/security/blog/2024/02/22/announcing-microsofts-open-automation-framework-to-red-team-generative-ai-systems/)</sup>

| 关键事实 | 详情 |
|---|---|
| 开发者 | 微软AI红队<sup>[2](https://arxiv.org/pdf/2410.02828)</sup> |
| 首次公开发布 | 2024年2月22日（PyPI 0.1.0于2024年2月21日上线）<sup>[1](https://www.microsoft.com/en-us/security/blog/2024/02/22/announcing-microsofts-open-automation-framework-to-red-team-generative-ai-systems/)</sup><sup> • </sup><sup>[5](https://pypi.org/project/pyrit/)</sup> |
| 许可证与语言 | MIT许可，Python<sup>[2](https://arxiv.org/pdf/2410.02828)</sup> |
| 当前版本 | v1.0.1（2026年）<sup>[4](https://github.com/microsoft/PyRIT/releases)</sup> |
| GitHub活跃度 | 4,381星标，852复刻，86个未关闭议题（2026年9月）<sup>[3](https://github.com/microsoft/pyrit)</sup> |
| 内部使用 | 100余次微软红队测试行动，包括Copilot系列和Phi-3发布<sup>[2](https://arxiv.org/pdf/2410.02828)</sup> |
| 组件 | 53+数据集，70+提示词转换器，6种攻击策略，20+评分器，10+目标<sup>[6](https://techcommunity.microsoft.com/blog/appsonazureblog/securing-your-ai-agents-before-they-ship-red-teaming-with-microsoft-pyrit/4515514)</sup> |

## PyRIT是什么

PyRIT是一个库，而非托管服务。安全专业人员和机器学习工程师从PyPI安装它，编写Python脚本将其指向目标系统、提供对抗性提示词并收集评分结果。<sup>[1](https://www.microsoft.com/en-us/security/blog/2024/02/22/announcing-microsofts-open-automation-framework-to-red-team-generative-ai-systems/)</sup><sup> • </sup><sup>[5](https://pypi.org/project/pyrit/)</sup> 该项目将其目的描述为帮助团队“主动识别生成式AI系统中的风险”，其定位是人工红队判断之上的自动化层，而非模型安全性的自主裁判。<sup>[1](https://www.microsoft.com/en-us/security/blog/2024/02/22/announcing-microsofts-open-automation-framework-to-red-team-generative-ai-systems/)</sup>

该框架源于实践而非研究计划。微软AI红队于2022年开始用一次性脚本对生成式AI系统进行红队测试；这些脚本被整合为工具包，GitHub仓库于2023年12月12日创建，随后于2024年2月22日公开发布。<sup>[1](https://www.microsoft.com/en-us/security/blog/2024/02/22/announcing-microsofts-open-automation-framework-to-red-team-generative-ai-systems/)</sup><sup> • </sup><sup>[3](https://github.com/microsoft/pyrit)</sup> 微软有意选择Python，理由是它易于使用且对社区友好。<sup>[2](https://arxiv.org/pdf/2410.02828)</sup>

## 工作原理

一次PyRIT运行遵循一个循环：编排器将数据集中的提示词经过转换器发送至目标，在内存中捕获回复，并将其传递给评分引擎，由评分引擎判定目标是否生成了有害内容。发布公告将此描述为五个接口：目标、数据集、评分引擎、攻击策略和内存。<sup>[1](https://www.microsoft.com/en-us/security/blog/2024/02/22/announcing-microsofts-open-automation-framework-to-red-team-generative-ai-systems/)</sup> 该框架根据目标的回复调整策略，迭代直至安全专业人员设定的目标达成，这使它有别于一份静态的越狱提示词清单——每条只发送一次。<sup>[1](https://www.microsoft.com/en-us/security/blog/2024/02/22/announcing-microsofts-open-automation-framework-to-red-team-generative-ai-systems/)</sup>

根据微软相关从业者的操作指南，当前的组件清单相当可观：<sup>[6](https://techcommunity.microsoft.com/blog/appsonazureblog/securing-your-ai-agents-before-they-ship-red-teaming-with-microsoft-pyrit/4515514)</sup>

- **数据集。** 53+对抗性数据集，包括AIRT、HarmBench、AdvBench和[XSTest](https://www.edgepedia.org/zh/xstest)。
- **提示词转换器。** 70+可堆叠的变换方式，如Base64、ROT13、Leetspeak、Unicode同形字、LLM驱动的改写、翻译和多模态注入。
- **攻击策略。** 六种，从单轮PromptSendingAttack到CrescendoAttack（跨轮次逐步升级）、TreeOfAttacksWithPruning（TAP）以及多轮对话攻击。
- **评分器。** 20+，从经典ML分类器和基于LLM的自我评估到Azure AI内容过滤器。<sup>[6](https://techcommunity.microsoft.com/blog/appsonazureblog/securing-your-ai-agents-before-they-ship-red-teaming-with-microsoft-pyrit/4515514)</sup><sup> • </sup><sup>[1](https://www.microsoft.com/en-us/security/blog/2024/02/22/announcing-microsofts-open-automation-framework-to-red-team-generative-ai-systems/)</sup>
- **目标。** 10+，包括OpenAI、Azure OpenAI、Hugging Face模型、AzureML托管在线端点、本地ONNX模型、HTTP端点、Playwright驱动的Web应用和[WebSocket](https://www.edgepedia.org/zh/websockets)。<sup>[1](https://www.microsoft.com/en-us/security/blog/2024/02/22/announcing-microsofts-open-automation-framework-to-red-team-generative-ai-systems/)</sup><sup> • </sup><sup>[2](https://arxiv.org/pdf/2410.02828)</sup><sup> • </sup><sup>[6](https://techcommunity.microsoft.com/blog/appsonazureblog/securing-your-ai-agents-before-they-ship-red-teaming-with-microsoft-pyrit/4515514)</sup>

PyRIT同时支持单轮攻击和多轮攻击：前者对单个提示词的回复进行孤立评估，后者由红队测试机器人迭代多个提示词以达成目标。<sup>[2](https://arxiv.org/pdf/2410.02828)</sup> 初始版本附带包含知名公开越狱提示词的提示集，微软指出多轮策略能以更高的计算成本实现更逼真的对抗行为，因为每一轮都会消耗额外的模型调用。<sup>[1](https://www.microsoft.com/en-us/security/blog/2024/02/22/announcing-microsofts-open-automation-framework-to-red-team-generative-ai-systems/)</sup> 请求和回复可以包含文本、音频和图像，因此同一循环可覆盖多模态目标。<sup>[2](https://arxiv.org/pdf/2410.02828)</sup>

## 发布历史与版本

PyRIT的首个PyPI版本（0.1.0）于2024年2月21日上传，比公告文章早一天。<sup>[5](https://pypi.org/project/pyrit/)</sup> 版本线随后从v0.9.0经v0.14.0推进至1.0。注册表记录显示：0.10.0于2025年12月13日，0.11.0于2026年2月5日，0.12.0于2026年3月27日，0.13.0于2026年4月17日，0.14.0于2026年6月5日，当前版本为v1.0.1。<sup>[5](https://pypi.org/project/pyrit/)</sup><sup> • </sup><sup>[4](https://github.com/microsoft/PyRIT/releases)</sup>

后期版本中有若干新增了针对特定漏洞类别的评分能力：映射至OWASP LLM01的PromptInjectionScorer、覆盖XSS、SQL注入、shell和路径载荷的OWASP LLM02输出侧包、RegexScorer和用于基于正则表达式检测机密信息的CredentialLeakScorer，以及0DIN JEF关键词评分器。<sup>[4](https://github.com/microsoft/PyRIT/releases)</sup> v1.0.x系列在各类评分器中新增了统一的错误与拦截回复评分，以及从被内容过滤的回复中对部分内容进行评分的能力——当目标的安全过滤器截断有害答案而非直接拒绝时，这一点尤为重要。<sup>[4](https://github.com/microsoft/PyRIT/releases)</sup> 某次发布还引入了CoPyRIT，一个被描述为预发布但已被微软AI红队使用的图形界面；发布说明称这是该GUI首次可用，“风险自负”。<sup>[4](https://github.com/microsoft/PyRIT/releases)</sup> 场景表还包括AIRT系列的Scam场景，用于在单轮和多轮模式下通过说服技巧生成钓鱼和欺诈材料。<sup>[4](https://github.com/microsoft/PyRIT/releases)</sup>

## 数据一览

以下使用情况与性能数据均为厂商报告；本文所涉公开记录中未见独立评估。

- **100余次行动。** 微软AI红队在其2024年10月的论文中报告称，截至当时已将PyRIT用于100余次生成式AI模型和应用的红队测试行动，包括Copilot系列和Phi-3模型发布。<sup>[2](https://arxiv.org/pdf/2410.02828)</sup>
- **Phi-3案例研究。** 在Phi-3系列的开源发布中，团队使用PyRIT在15个危害类别（包括CBRN、钓鱼和网络安全、选举关键信息、公平性与偏见、仇恨言论以及性和暴力内容）下，以两种对手人设（低技能和中等技能）及单轮和多轮场景，对文本和视觉发布候选版本进行探测和评估。数据集准备耗时六周，产出数百条提示词和提示词-图像对；超过一千条提示词被生成、规范化、提交推理并评分。<sup>[2](https://arxiv.org/pdf/2410.02828)</sup>
- **Copilot演练。** 在一次针对Copilot系统的红队测试演练中，微软报告称选定一个危害类别，生成数千条恶意提示词，并用PyRIT的评分引擎“在数小时内而非数周内”对Copilot系统的输出进行了评分。<sup>[1](https://www.microsoft.com/en-us/security/blog/2024/02/22/announcing-microsofts-open-automation-framework-to-red-team-generative-ai-systems/)</sup>
- **社区规模。** 截至2026年9月检索时，该仓库有4,381星标、852复刻和86个未关闭议题；<sup>[3](https://github.com/microsoft/pyrit)</sup> 一篇较早的微软相关文章引用约3,800星标和129名贡献者。<sup>[6](https://techcommunity.microsoft.com/blog/appsonazureblog/securing-your-ai-agents-before-they-ship-red-teaming-with-microsoft-pyrit/4515514)</sup>

关于结果，微软报告称，在AI红队测试指导下进行的安全后训练使Phi-3-mini在所有测试类别中的有害内容生成显著减少。<sup>[2](https://arxiv.org/pdf/2410.02828)</sup> 这是厂商关于自家模型的声明；记录中没有第三方对此的测量。

## 使用者与用途

有据可查的用户是微软自身：AI红队的100余次行动涵盖Copilot系统和Phi-3模型发布前的发现问题与修复周期，红队测试人员在发布候选版本中探查安全与安保问题，结果反馈至后训练修复。<sup>[2](https://arxiv.org/pdf/2410.02828)</sup> 微软之外，采用证据是间接的：GitHub上的星标、复刻和贡献者数量，<sup>[3](https://github.com/microsoft/pyrit)</sup><sup> • </sup><sup>[6](https://techcommunity.microsoft.com/blog/appsonazureblog/securing-your-ai-agents-before-they-ship-red-teaming-with-microsoft-pyrit/4515514)</sup> 以及描述如何将PyRIT封装进CI/CD流水线和OWASP映射扫描工作流的从业者指南。公开记录中没有来源点名在生产中使用PyRIT的外部企业。

## 反响、局限与批评

从业者的主要批评是结构性的：PyRIT是工具包，不是流水线。它提供的是构建模块，要在真实工程工作流（CI/CD门禁、发布检查或OWASP映射扫描）中发挥作用，用户必须自己编写封装代码。<sup>[6](https://techcommunity.microsoft.com/blog/appsonazureblog/securing-your-ai-agents-before-they-ship-red-teaming-with-microsoft-pyrit/4515514)</sup> 发布公告另外指出了多轮策略的成本不对称：相比单轮提示词发送，多轮策略消耗更多计算资源，因为每一次升级轮次都是又一次模型调用。<sup>[1](https://www.microsoft.com/en-us/security/blog/2024/02/22/announcing-microsofts-open-automation-framework-to-red-team-generative-ai-systems/)</sup>

微软自身的定位设定了第二个局限：该工具增强而非替代人类专业知识，因此结果取决于人工操作者选择的危害类别、人设和数据集。<sup>[1](https://www.microsoft.com/en-us/security/blog/2024/02/22/announcing-microsofts-open-automation-framework-to-red-team-generative-ai-systems/)</sup> 除此之外，记录中没有系统性的独立批评、没有可复现性研究，也没有与Garak或DeepTeam等竞争框架的已发表对比；PyRIT与这些替代方案相比如何，现有来源尚无定论。

## References

1. [Announcing Microsoft's open automation framework to red team generative AI systems (Microsoft Security Blog, February 22, 2024)](https://www.microsoft.com/en-us/security/blog/2024/02/22/announcing-microsofts-open-automation-framework-to-red-team-generative-ai-systems/)
2. [PyRIT: A Framework for Security Risk Identification and Red Teaming in Generative AI Systems (Microsoft AI Red Team, arXiv, October 2024)](https://arxiv.org/pdf/2410.02828)
3. [microsoft/PyRIT GitHub repository](https://github.com/microsoft/pyrit)
4. [Releases · microsoft/PyRIT (GitHub)](https://github.com/microsoft/PyRIT/releases)
5. [pyrit on PyPI (v1.0.1)](https://pypi.org/project/pyrit/)
6. [Securing Your AI Agents Before They Ship: Red Teaming with Microsoft PyRIT (Microsoft Tech Community)](https://techcommunity.microsoft.com/blog/appsonazureblog/securing-your-ai-agents-before-they-ship-red-teaming-with-microsoft-pyrit/4515514)

---
*Initially written Sep 17, 2026 · Edited: Oct 11, 2026; Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 现代人工智能：基础模型、生成式人工智能与人工智能产业 › AI companies, people, and products › AI products and assistants › AI agents and developer tools

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/pyrit

English original: https://www.edgepedia.org/pyrit
