Merged
Conversation
Contributor
Author
|
@microsoft-github-policy-service agree |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new prompt converter that outputs Word .docx documents to support indirect prompt-injection scenarios, and wires it into the prompt-converter discovery surface.
Changes:
- Introduces
word_doc_converter.pyimplementing.docxgeneration and placeholder-based injection for existing documents. - Exposes the new converter via
pyrit.prompt_converter.__init__so it participates in converter discovery. - Adds
python-docxas a project dependency.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
pyrit/prompt_converter/word_doc_converter.py |
New Word .docx converter with new-doc generation and placeholder injection logic, plus identifier + serialization. |
pyrit/prompt_converter/__init__.py |
Exports the new converter for discovery via __all__ / get_converter_modalities. |
pyproject.toml |
Adds python-docx runtime dependency needed by the converter. |
Contributor
Author
|
Hi @romanlutz , could you please go through the new changes that have been made? |
- Fix __all__ ordering in __init__.py (VariationSelectorSmugglerConverter before WordDocConverter) - Fix ruff DOC201/DOC501 lint errors: add Returns/Raises sections to docstrings - Fix mypy errors: remove unused type: ignore comments, convert Path to str for Document() - Remove dead code branches (isinstance checks on str-typed param) - Add copyright notice to test file - Add comprehensive unit tests: constructor validation, _build_identifier, _prepare_content with templates, _generate_new_docx, custom/multiple placeholders, warning on missing placeholder, _replace_placeholder_in_paragraph, end-to-end tests - Add WordDocConverter documentation to 5_file_converters.py with examples for both new document generation and placeholder-based injection - Regenerate 0_converters.ipynb and 5_file_converters.ipynb notebooks Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
romanlutz
approved these changes
Feb 20, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Implemented a Word document file converter to support indirect prompt injection scenarios, addressing FEAT File Converter: Word Document (#424).
Feature: WordDoc_Converter
Added WordDoc_Converter in pyrit.prompt_converter.word_doc_converter as a PromptConverter that transforms text prompts into .docx files.
Exposed via pyrit.prompt_converter.init for discovery through get_converter_modalities.
Supported Modes
New Document Generation
Creates a simple .docx with optionally templated prompt content in a single paragraph.
Placeholder-Based Injection
Replaces a literal placeholder in an existing .docx (within paragraph runs) with rendered content while preserving formatting.
Templating and Safety
Uses SeedPrompt.render_template_value for templating.
Does not render Jinja2 templates from arbitrary .docx content.
Injected content is plain text output from SeedPrompt.
Formatting Constraints
Placeholders must be fully contained within a single run.
If spanning multiple runs, replacement is skipped and a warning is logged to avoid formatting issues.
Tests
Added unit tests for:
Creating a new .docx from a plain text prompt.
Injecting content when the placeholder is within a single run.
Verifying no replacement and warning when placeholders span multiple runs.
Documentation
Updated documentation to describe:
WordDoc_Converter
Supported modes
Placeholder requirements
Use of SeedPrompt for templating