You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BUG TokenBijectionConverter cannot represent a literal hyphen, so "e-mail" encodes identically to "email" and decodes without the hyphen #3128
TokenBijectionConverter (pyrit/converter/bijection_converter.py) joins the code words of one plaintext word with - (_TOKEN_DELIMITER), and encode() passes every unmapped character through unchanged. A hyphen in the plaintext is therefore emitted as the same character as the delimiter, and lands between two code-word runs exactly where an inserted delimiter would. decode()'s pattern (\b(tok)(?:-(tok))*\b) consumes it as a delimiter, so the hyphen disappears:
plaintext
encoded (mapping x -> xxx)
decoded
email
eee-mmm-aaa-iii-lll
email
e-mail
eee-mmm-aaa-iii-lll
email
self-harm
sss-eee-lll-fff-hhh-aaa-rrr-mmm
selfharm
The class docstring says the delimiter is there "to keep them legible and unambiguously decodable", and the teaching instructions tell the target to "join adjacent code words with hyphens", which leaves the model no way to write a literal hyphen either. So the prompt sent to the target loses hyphens on the way in ("self-harm" becomes "selfharm" once decoded), and any hyphen in the target's answer is lost on the way back.
This is the same collision class that has already been fixed twice in this file: #2696 (literal apostrophes vs. _CASE_MARKER) and #2741 (literal digits vs. digit tokens) in DigitBijectionConverter. The hyphen case in TokenBijectionConverter was not covered.
Hyphens that are not directly between two letters (a - b, -lead, trail-) happen to survive because the decode pattern requires a code word on both sides, so the loss is specific to hyphenated words, which is the common case.
Suggested fix
Escape a literal hyphen as a doubled delimiter (--) on encode, the same way DigitBijectionConverter doubles a literal apostrophe or tilde, and have the decode pattern match -- first and restore it to one hyphen. A doubled delimiter can never be produced by joining code words, so it is unambiguous. The teaching instructions should tell the target to write a literal hyphen as two hyphens.
I have the fix with regression tests ready and can open the PR. The new round-trip cases fail on main (6 failed) and pass with the change; tests/unit/converter passes in full.
Versions
OS: macOS 26.5
Python version: 3.14.8
PyRIT version: 1.2.0.dev0, installed from main (0a5abbf9) in editable mode
Activity
kushaltalati commentedon Oct 11, 2026
Opened #3129 with the fix and regression tests.