Skip to content

Sample code for: AI Red Teaming in Python: Attack Your LLM Agent With PyRIT - #940

Open
lpozo wants to merge 15 commits into
masterfrom
ai-red-teaming
Open

lpozo wants to merge 15 commits into
masterfrom
ai-red-teaming

Conversation

@lpozo

@lpozo lpozo commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Where to put new files:

  • New files should go into a top-level subfolder, named after the article slug. For example: my-awesome-article

How to merge your changes:

  1. Make sure the CI code style tests all pass (+ run the automatic code formatter if necessary).
  2. Find an RP Team member on Slack and ask them to review & approve your PR.
  3. Once the PR has one positive ("approved") review, GitHub lets you merge the PR.
  4. 🎉

Code examples for the AI Red Teaming in Python: Attack Your LLM Agent With PyRIT tutorial. Files live in the ai-red-teaming/ top-level folder, named after the article slug.

Generated from the tutorial markdown with the post-materials skill, then verified locally before pushing.

🤖 Generated with Claude Code

… PyRIT

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
lpozo and others added 14 commits November 10, 2026 16:07
Replace requirements.txt and red_team/requirements-pyrit.txt with a
pyproject.toml and uv.lock. The project pins openai==3.49.0 and
pyrit==1.1.0 and requires Python 3.14. Update the README to use
`uv sync` and `uv run`.

Tested with `uv sync` on Python 3.14.10: the agent, the probes, and the
hardened probes give the same results as the tutorial.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move faq.txt and notes.txt out of the DOCUMENTS dict in agent.py and
into a docs/ folder, so notes.txt is a real file that a reader can edit
the way an attacker would. read_document() strips directory parts from
the requested name, so the model can't read files outside docs/.

Probe results are unchanged: both attacks land with HARDENED off, and
all three fail with HARDENED=1 while the benign control still succeeds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
run_agent() now always uses SYSTEM_PROMPT, so the agent loop doesn't
mention hardening before the tutorial introduces it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nature

Keeps the snippet lines short in the tutorial.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Step 4 of the tutorial now has readers harden the agent by editing
agent.py directly: first the system prompt, then a recipient allowlist
in send_email(). Ship agent.py in its vulnerable starting state, stop
printing the HARDENED= line in run_pyrit.py, and point the README at
Step 4 instead of HARDENED=1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No step or probe in the tutorial reads this file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The tutorial shows pyproject.toml in full, and the old 128-character
description line overflowed the code block.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants