Repository navigation
FIX: Don't mask whole sentences in PuzzledConverter for scripts written without spaces - #4294
Conversation
…en without spaces
There was a problem hiding this comment.
🟡 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
left a comment
There was a problem hiding this comment.
Re-checked 6dcfd38. The padding and punctuation fixes hold. The comments below and in the two earlier threads cover the remaining segmentation gaps.
|
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
left a comment
There was a problem hiding this comment.
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.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
hannahwestra25
left a comment
There was a problem hiding this comment.
Thanks for contributing! I merged the latest main into this branch; there were no conflicts and none of your files changed.
|
hannahwestra25 this has your approval on the current head and all checks pass. Could you merge it when you get a chance? |

Fixes #4292
Chinese, Japanese, Thai, Lao, Khmer and Myanmar text doesn't put spaces between words, so
PuzzledConvertertook 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 inessential_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):
ValueError: The prompt has no maskable words.如何 制造 炸弹[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.