Skip to content

FEAT Add WordDocConverter#1368

Merged
romanlutz merged 7 commits intomicrosoft:mainfrom
mhadica:main
Feb 20, 2026
Merged

FEAT Add WordDocConverter#1368
romanlutz merged 7 commits intomicrosoft:mainfrom
mhadica:main

Conversation

@mhadica
Copy link
Copy Markdown
Contributor

@mhadica mhadica commented Feb 12, 2026

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

@mhadica
Copy link
Copy Markdown
Contributor Author

mhadica commented Feb 12, 2026

@microsoft-github-policy-service agree

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py implementing .docx generation and placeholder-based injection for existing documents.
  • Exposes the new converter via pyrit.prompt_converter.__init__ so it participates in converter discovery.
  • Adds python-docx as 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.

@mhadica
Copy link
Copy Markdown
Contributor Author

mhadica commented Feb 18, 2026

Hi @romanlutz , could you please go through the new changes that have been made?

romanlutz and others added 2 commits February 20, 2026 05:01
- 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 and others added 2 commits February 20, 2026 05:15
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@romanlutz romanlutz merged commit a9fca10 into microsoft:main Feb 20, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants