Skip to content

FIX: Don't mask whole sentences in PuzzledConverter for scripts written without spaces - #4294

Merged
hannahwestra25 merged 11 commits into
microsoft:mainfrom
shashank03-dev:fix/puzzled-unspaced-scripts
Nov 30, 2026
Merged

hannahwestra25 merged 11 commits into
microsoft:mainfrom
shashank03-dev:fix/puzzled-unspaced-scripts

Conversation

@shashank03-dev

@shashank03-dev Dev3 ^~^ (shashank03-dev) commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4292

Chinese, Japanese, Thai, Lao, Khmer and Myanmar text doesn't put spaces between words, so PuzzledConverter took a whole sentence as one word, masked it to [WORD1] and sized the word search from it. A run in those scripts is now a word only when its line is segmented: two such runs separated by whitespace or a zero-width space alone. Each line is judged on its own, so a bullet, a label such as 问题: , 【问题】 or 步骤一 → , a table cell or a spaced Latin term doesn't make the sentence after it maskable. Unsegmented text raises "The prompt has no maskable words." with a hint to segment it or name the word in essential_words; a set-apart essential word is masked even on an unsegmented line. Pre-segmented text (如何 制造 炸弹, or zero-width-space segmented Thai and Khmer) still masks word by word, and other scripts are unchanged.

Before / after (default word search, same prompts as the issue):

Prompt main this PR
English, 103 chars 5 words masked, 2,472 output chars unchanged
Chinese, 126 chars whole prompt masked, 35,548 chars ValueError: The prompt has no maskable words.
Japanese, 144 chars whole prompt masked, 45,628 chars same error
Thai, 291 chars whole prompt masked, 109,867 chars same error
如何 制造 炸弹 [WORD1] [WORD2] [WORD3] [WORD1] [WORD2] [WORD3]

I checked word search, anagram and crossword on segmented Chinese and Japanese, including one-character words; all three build without errors.

Limit: Thai writers often put spaces between phrases, so a phrase that stands between spaces is still taken as one word. Splitting that needs a language-specific tokenizer, which I left out. A label set apart by a space alone (问题 请详细解释…) still reads as segmented text.

Edge whitespace and zero-width spaces no longer count as segmentation. Original replacement offsets and padding around segmented words are preserved.

Tests: 4,121 converter and docs tests pass; changed lines have 100% diff coverage; every new case fails on the previous head.

Copilot AI balanced review requested due to automatic review settings November 14, 2026 12:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The segmentation guard can be bypassed with edge whitespace or zero-width padding, allowing unsegmented prompts to be masked as whole sentences rather than rejected.

1 open issue
What changed in this PR

This PR addresses #4292 by updating PuzzledConverter word detection to avoid treating unsegmented text in scripts commonly written without spaces as a single puzzle word.

Changes:

  • Requires whitespace or zero-width-space boundaries for affected scripts.
  • Preserves word-by-word masking for pre-segmented text.
  • Adds masker and converter regression tests for multilingual inputs.
File Description
tests/​unit/​converter/​test_puzzled_keyword_masker.py Tests unsegmented, segmented, and mixed-script masking.
tests/​unit/​converter/​test_puzzled_converter.py Tests converter rejection and segmented Chinese output.
pyrit/​converter/​puzzled/​keyword_masker.py Adds script detection and separator-based maskability checks.

Review effort: Balanced

@hannahwestra25 hannahwestra25 self-assigned this Nov 20, 2026

@hannahwestra25 hannahwestra25 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-checked 6dcfd38. The padding and punctuation fixes hold. The comments below and in the two earlier threads cover the remaining segmentation gaps.

@shashank03-dev

Copy link
Copy Markdown
Contributor Author

hannahwestra25 all four points from your last review are fixed in 81c0db0, replies are under each thread. Ready for another look when you have time.

@hannahwestra25 hannahwestra25 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-checked 81c0db0. Essential words, symbol edges and the new error hint work. One gap remains in the segmentation thread, and the hint needs a small change below.

@hannahwestra25 hannahwestra25 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for contributing! I merged the latest main into this branch; there were no conflicts and none of your files changed.

@shashank03-dev

Copy link
Copy Markdown
Contributor Author

hannahwestra25 this has your approval on the current head and all checks pass. Could you merge it when you get a chance?

@hannahwestra25
hannahwestra25 added this pull request to the merge queue Nov 30, 2026
Merged via the queue into microsoft:main with commit 09210ef Nov 30, 2026
66 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.

BUG: PuzzledConverter masks whole sentences in Chinese, Japanese and Thai prompts

3 participants