PyRIT is Microsoft's open-source red-teaming framework. It orchestrates adaptive multi-turn attacks against an LLM system, with pluggable converters, strategies, and scorers, and produces attack success rate metrics.
Imagine testing a castle's defences. The lazy way is to walk around the walls once with the same set of test attacks, write down what worked, and call it done. The thorough way is to bring an entire team. One person crafts new attempts. Another adjusts them based on what the previous one tried. A third decides whether each attempt breached the wall. A coordinator runs the whole exercise over hours and rotates tactics. PyRIT is the second approach for LLM systems. It is not a list of attacks to try. It is an orchestration framework where attackers learn from previous turns and adapt, and scorers automatically judge success. You get back a metric of how well your model held up across many attack families.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Red-teaming an LLM used to mean assembling a small group of clever attackers, giving them a model endpoint, and asking them to find ways to break it. The output was a writeup. That model has three problems. It does not scale, it does not compose with CI, and it does not produce metrics that can be tracked over time across releases. Microsoft AI Red Team open-sourced PyRIT in 2024 to industrialise the practice. The goal was to turn red-team into a framework you can run on every build, with adaptive multi-turn attacks, pluggable strategies, and metrics that gate releases.
PyRIT is the CI for safety. A dataset is the unit test; PyRIT is the orchestration that ties many tests together into a regression suite with adaptive depth.
The four-component architecture
Target
A target wraps the system under test. PyRIT ships targets for OpenAI, Azure, Anthropic, Hugging Face and HTTP endpoints, and custom targets are a small class. The right granularity is the user-facing endpoint, not the bare model. Testing the model alone misses stack-specific weaknesses (system prompts, retrieval, tool definitions) that are part of the real attack surface.
Multimodal targets (text plus image) are supported. A full agent pipeline can be wrapped as a custom or HTTP target.
Red agent
The red agent generates attack attempts. PyRIT supports several modes:
- LLM-driven red agent. An adversarial chat model (for example an uncensored open-weights model) prompted to generate adversarial inputs. The red LLM can read previous-turn responses and refine.
- Deterministic red agent. A pattern generator that emits attacks from templates with parameters. It is useful for reproducibility.
- Hybrid. Deterministic base prompts wrapped by LLM-generated paraphrase or context.
The choice depends on the attack family: jailbreaks benefit from LLM-driven creativity, and encoded-payload tests suit deterministic generation.
Scorer
The scorer is the decisive component for ASR validity. Scorers come in true/false and float-scale families:
- Substring scorers. Did the response contain a forbidden token? They are cheap and brittle.
- True/false LLM-judge scorers. Ask an LLM-as-judge: did this response comply with the off-policy request? They are nuanced but only as good as the judge.
- Classification scorers. An LLM judge assigns the response to a fixed category set.
- Likert and float-scale scorers. A judge gives a graded score instead of a yes or no.
- Chained scoring. Combine scorers (for example fast keyword triage, then LLM-judge confirmation).
Production setups chain a fast scorer for triage with a cross-vendor LLM-as-judge for confirmation. A judge from another vendor is less likely to share the target's blind spots.
Attack (executor)
The attack implements the iteration policy. Built-in options include:
- PromptSendingAttack. Single-turn sender and the building block for the others.
- RedTeamingAttack. Multi-turn conversational attack with a red LLM driving turns.
- PAIR (Prompt Automatic Iterative Refinement). The red LLM refines a prompt across attempts based on judge feedback.
- TreeOfAttacksWithPruningAttack (TAP). Branching exploration with pruning to manage cost.
- CrescendoAttack. Gradually escalates context to bypass safety calibration.
- ManyShotJailbreakAttack. Builds long-context attacks with many fake compliance examples.
Each attack is a class. Writing custom ones for organisation-specific attack families is straightforward.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- Microsoft AI Red Team built PyRIT and open-sourced it in 2024. It is developed at github.com/microsoft/PyRIT.
- PyRIT ships Crescendo (Russinovich, Salem and Eldan, Microsoft, 2024) as a built-in multi-turn attack that starts benign and escalates by referring back to the model's own replies.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow would you design the scorer for a high-stakes safety regression run?
Chain a fast keyword scorer for triage with a cross-vendor LLM-as-judge for confirmation. Use a fixed scorer prompt and model for at least the regression window so ASR is comparable across releases. Calibrate the scorer quarterly against human labels on a held-out sample.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Treating PyRIT as a dataset of attack prompts. PyRIT is an orchestration framework. The attacks are adaptive and multi-turn, not a fixed list to evaluate against.
60 second bullets to scan on the way to the call.
The four core PyRIT components (target, red agent, scorer, attack)
Pluggable converters (encoding, paraphrase, role-play wrap)
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.