Repository navigation
FIX: AsciiSmugglerConverter replaces characters with ASCII equivalents - #4437
Open
hannahwestra25 wants to merge 2 commits into
Open
hannahwestra25 wants to merge 2 commits into
hannahwestra25 wants to merge 2 commits into
Conversation
Dataset objectives with newlines or typographic punctuation (en dashes, curly quotes) made AsciiSmugglerConverter raise, failing foundry.red_team_agent and garak encoding scans. Characters with a faithful ASCII equivalent are now replaced (whitespace -> space, dashes -> '-', curly quotes -> straight, ellipsis -> '...', accents removed via NFKD). Characters with no equivalent, such as CJK or emoji, still raise so nothing is silently dropped. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The default DecodingScorer incorrectly rejects successfully decoded normalized text because it compares against the unchanged original value, requiring the normalized plaintext to reach scoring and a regression test.
1 open issue
What changed in this PR
This PR expands AsciiSmugglerConverter to accept common Unicode characters with printable ASCII replacements, reducing conversion failures for dataset objectives while retaining errors for unsupported characters.
Changes:
- Normalize whitespace, typographic punctuation, and decomposable Unicode before tag encoding.
- Add tests for normalized round trips and continued rejection of unsupported input.
- Update the paired scenario documentation to explain replacement behavior and filtering.
| File | Description |
|---|---|
tests/unit/converter/test_ascii_smuggler_converter.py |
Tests ASCII replacements and unsupported-character rejection. |
pyrit/converter/token_smuggling/ascii_smuggler_converter.py |
Normalizes supported characters before Unicode-tag encoding. |
doc/code/scenarios/1_common_scenario_parameters.py |
Updates guidance on normalization and seed filtering. |
doc/code/scenarios/1_common_scenario_parameters.ipynb |
Mirrors the updated guidance in the notebook. |
Review effort: Balanced
Store the AsciiSmugglerConverter-normalized seed text as decoded_text metadata so DecodingScorer accepts a correct decode of normalized punctuation. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This branch has not been deployed
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
Running
foundry.red_team_agent(or Garak encoding) withascii_smugglerfailed the whole scan whenever a dataset objective contained newlines or typographic punctuation. Since #2540,AsciiSmugglerConverterraises on any character outside printable ASCII. This PR replaces characters that have a faithful ASCII equivalent and keeps the raise for everything else, so nothing is silently dropped.\n,\t, NBSP and em space becomes a space. En/em dashes and minus become-. Curly quotes and primes become straight quotes.…becomes....é→e, fullwidthA→A,fi→fi).ValueError.AsciiSmugglerConverternote indoc/code/scenarios/1_common_scenario_parameters.{py,ipynb}.Before:
ValueError: Cannot encode 18 character(s) outside the ASCII printable range (0x20-0x7E): '–\n\n…’…'After: the objective is smuggled as
**Tom Harris - IT Chronicles** Welcome...