Skip to content

FIX: AsciiSmugglerConverter replaces characters with ASCII equivalents - #4437

Open
hannahwestra25 wants to merge 2 commits into
microsoft:mainfrom
hannahwestra25:hannahwestra25-fix-ascii-smuggler-scenario-failure
Open

hannahwestra25 wants to merge 2 commits into
microsoft:mainfrom
hannahwestra25:hannahwestra25-fix-ascii-smuggler-scenario-failure

Conversation

@hannahwestra25

Copy link
Copy Markdown
Collaborator

Description

Running foundry.red_team_agent (or Garak encoding) with ascii_smuggler failed the whole scan whenever a dataset objective contained newlines or typographic punctuation. Since #2540, AsciiSmugglerConverter raises 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.

  • Whitespace such as \n, \t, NBSP and em space becomes a space. En/em dashes and minus become -. Curly quotes and primes become straight quotes. … becomes ....
  • Any other character is passed through NFKD with combining marks removed, and is used only if the result is non-empty printable ASCII (é → e, fullwidth A → A, fi → fi).
  • Characters with no equivalent (CJK, emoji, zero-width space, lone combining marks, other control characters) still raise ValueError.
  • Both affected scenarios are fixed without any scenario changes.
  • Updated the AsciiSmugglerConverter note in doc/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...

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>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 20:35

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 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>
@jbolor21 jbolor21 self-assigned this Nov 19, 2026

This branch has not been deployed

No deployments
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