Repository navigation
Description
For people who want to contribute/help with this issue:
- Follow the general guidelines for contributing to PyRIT: https://azure.github.io/PyRIT/contributing/README.html
- Pick one or more modules from the list below and comment below which module(s) you're working on to avoid duplication of effort
- Remove the module(s) from
tool.ruff.lint.per-file-ignoresinpyproject.tomlso that docstring issues are no longer ignored there - Run
ruff checkorpre-commit run ruff-check --all-filesto see what issues to fix - Fix the issues
- Verify completion:
ruff checkshould report "All checks passed!" - Submit a PR referencing this issue
Here's a list of modules with the number of docstring issues in each:
-
pyrit/analytics: 5 Riyosha Sharma (@riyosha) -
pyrit/auth: 12 Riyosha Sharma (@riyosha) -
pyrit/chat_message_normalizer: 13 Riyosha Sharma (@riyosha) -
pyrit/cli: 2 Riyosha Sharma (@riyosha) -
pyrit/common: 47 Paulina Kalicka (@paulinek13) -
pyrit/datasets: 34 Paulina Kalicka (@paulinek13) -
pyrit/embedding: 5 Riyosha Sharma (@riyosha) -
pyrit/exceptions: 26 Roman Lutz (@romanlutz) -
pyrit/executor: 92 Evelyne Lee (@eve1ne) -
pyrit/memory: 154 hatimoua -
pyrit/models: 146 Roman Lutz (@romanlutz) -
pyrit/prompt_converter: 387 Paulina Kalicka (@paulinek13) -
pyrit/prompt_normalizer: 15 Paulina Kalicka (@paulinek13) -
pyrit/prompt_target: 209 Paulina Kalicka (@paulinek13) -
pyrit/scenarios: 9 Evelyne Lee (@eve1ne) -
pyrit/score: 117 Paulina Kalicka (@paulinek13) -
pyrit/setup: 18 Evelyne Lee (@eve1ne)
The issues are mostly related to missing docstrings for public classes/methods/functions as well as missing parameter/return documentation.
Original post from 07XI25 "SUGGESTION: enforce docstring consistency in PyRIT with Ruff":
Related issue: #653
In short, this issue proposes adding Ruff as a dev dependency to enforce documentation consistency in PyRIT.
Why
PyRIT currently lacks automated verification of docs consistency.
The proposed solution will automatically check for the docstring requirements defined in the project's style guide (.github/instructions/style-guide.instructions.md), including:
- Google-style docstring format
- Type information in parameter descriptions
- Documented return values
- Documented exceptions (Raises sections)
- Triple quotes for all docstringsIt will also ensure that, for example, new public classes/methods/functions actually are documented to prevent missing entries in the docs.
Of course, things like that can be manually reviewed during PR reviews, but this could be easily automated + this change makes it now easier in fixing #653, I think.
Proposed Solution
As stated above, the proposal is to add Ruff as a new dev dependency, configure it properly to match as much of the existing style as possible, and add ruff check pyrit/ to the .pre-commit-config.yaml.
https://pypi.org/project/ruff/
https://docs.astral.sh/ruff/
In future ruff could replace flake8/isort/pylint in PyRIT, but for now, I'm proposing to add it just for docs checks.
More info
ruff check pyrit\ takes about 200-600 ms, so it's super fast.
Currently, there are about 1700 "errors":
config I've used:
[tool.ruff.lint.pydocstyle]
convention = "google"
[tool.ruff.lint]
preview = true
select = [
"D", # https://docs.astral.sh/ruff/rules/#pydocstyle-d
"DOC" # https://docs.astral.sh/ruff/rules/#pydoclint-doc
]
ignore = [
"D100", # Missing docstring in public module
"D200", # One-line docstring should fit on one line
"D205", # 1 blank line required between summary line and description
"D212", # Multi-line docstring summary should start at the first line
"DOC502", # Raised exception is not explicitly raised: {id}
]
extend-select = [
"D204", # 1 blank line required after class docstring
"D213", # Multi-line docstring summary should start at the second line
"D401", # First line of docstring should be in imperative mood: "{first_line}"
"D404", # First word of the docstring should not be "This"
]
Activity
romanlutz commentedon Nov 8, 2025
I'm all for this. It should be part of the pre commit config. We should at the same time evaluate which parts of the existing config are no longer useful. However, fixing 1800 issues is probably going to take a little while. I wonder if we can do it in batches?
paulinek13 commentedon Nov 11, 2025
Thanks for the feedback. We can certainly do this in batches.
Comment content:
I've divided the docstring errors into two main categories:
The plan is as follows:
I will start with a PR that adds Ruff as a dev dependency along with the initial doc-related config. The same PR will also fix all errors from the first group across the repo (as they are mostly "mechanical" changes and easy to fix in one go).
Subsequent PRs would address the second group of errors broken down by modules to keep the PRs manageable. These PRs would need to ensure that all Ruff docstring errors in the targeted module(s) are fixed (
ruff check pyrit/module1 pyrit/module2-> "All checks passed!")Once all the above is done, we can add Ruff to the precommit so that future PRs are blocked if they introduce docs issues.
As for the second point, I think we could track the overall progress of this effort. Maybe a checklist of modules to be done, so (new) contributors can pick/claim one (or more) and work on it.
Does this sound like a good approach?
romanlutz commentedon Nov 12, 2025
Sounds fantastic. I think you can just add a "list" to the original post and I'll add a tag with "help wanted" so people can find this.
[-]SUGGESTION: enforce docstring consistency in PyRIT with Ruff[/-][+]TASK: enforce docstring consistency in PyRIT with Ruff[/+][-]TASK: enforce docstring consistency in PyRIT with Ruff[/-][+]TASK: improve docstrings completeness and quality across PyRIT modules[/+]paulinek13 commentedon Nov 12, 2025
Roman Lutz (@romanlutz)
Do you think we could ignore docstring issues in
pyrit/uiandpyrit/auxiliary_attackssince they are not exposed in the public API Reference?romanlutz commentedon Nov 13, 2025
They should be in the API reference. It's mostly an oversight that they're not... You can ignore them for the moment (if it's possibly to exclude directories) and I'll get to that at some point.
riyosha commentedon Nov 16, 2025
Hi I'd like to contribute! I'm working on 2bmodules initially:
pyrit/analytics: 5
pyrit/auth: 12
I'm waiting for 1181 to be merged before I raise a PR. Thanks!
romanlutz commentedon Nov 17, 2025
Riyosha Sharma (@riyosha) I just merged #1181 so feel free to pull the changes and get started 😉
riyosha commentedon Nov 18, 2025
Thanks! Just raised a PR. I will also take up modules
if the PR looks okay!
11 remaining items
romanlutz commentedon Dec 2, 2025
Sounds good! I would only recommend holding off on "prompt_target" until I'm done with #1194 because a lot will change there.
hatimoua commentedon Dec 4, 2025
Hi, i'm a student and I would like to help with pyrit/memory. I can start working on the docstrings for this module.
MAINT: Improve docstrings in pyrit/memory (microsoft#1176)
MAINT: Fix docstrings for pyrit/executor modules (partial microsoft#1176
eve1ne commentedon Dec 5, 2025
Hi! I just raised a PR for pyrit/executor, if everything looks good with that I can move on to pyrit/models.
romanlutz commentedon Dec 6, 2025
It looks great! Feel free to move on to the next one.
MAINT: Fix docstrings for pyrit/executor modules (partial #1176) (#1225)
MAINT: Improve docstrings completeness in pyrit/memory (microsoft#1176)
mayank0030 commentedon Jan 29, 2026
Hi, I’d like to work on the pyrit/cli module for this issue.
romanlutz commentedon Feb 23, 2026
Self-assigned the last two to get this closed out. Thanks, everyone!
The ui/auxiliary_attacks modules are deprecated (or about to be) and do not need to be addressed.
fix: address review comments - logger.exception, f-string space, remo…
Remove stale comment referencing closed issue microsoft#1176