From ed882ecec9b77172ab5934f6a9482a94f687abd1 Mon Sep 17 00:00:00 2001 From: Roman Lutz Date: Thu, 19 Nov 2026 22:01:23 -0800 Subject: [PATCH 1/3] FEAT: Add disemvowel Encoding technique via SearchReplaceConverter Per review (reuse and compose before adding): keep the disemvowel technique but implement it with SearchReplaceConverter(pattern='[AEIOUaeiou]', replace='') instead of a dedicated DisemvowelConverter class. Co-Authored-By: Claude Opus 4.8 --- pyrit/scenario/scenarios/garak/encoding.py | 5 +++++ .../unit/scenario/garak/test_disemvowel_technique.py | 11 +++++++++++ tests/unit/scenario/garak/test_encoding.py | 3 ++- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/unit/scenario/garak/test_disemvowel_technique.py diff --git a/pyrit/scenario/scenarios/garak/encoding.py b/pyrit/scenario/scenarios/garak/encoding.py index a427f02596..a269d18fee 100644 --- a/pyrit/scenario/scenarios/garak/encoding.py +++ b/pyrit/scenario/scenarios/garak/encoding.py @@ -23,6 +23,7 @@ MorseConverter, NatoConverter, ROT13Converter, + SearchReplaceConverter, ZalgoConverter, ) from pyrit.executor.attack import AttackConverterConfig, AttackScoringConfig, PromptSendingAttack @@ -129,6 +130,7 @@ class EncodingTechnique(ScenarioTechnique): AsciiSmuggler = ("ascii_smuggler", set[str]()) Bifid = ("bifid", set[str]()) ColumnarTransposition = ("columnar_transposition", set[str]()) + Disemvowel = ("disemvowel", set[str]()) @classmethod def get_aggregate_tags(cls) -> set[str]: @@ -317,6 +319,9 @@ def _converter_variants() -> list[tuple[list[Converter], str, str]]: ([AsciiSmugglerConverter()], "ascii_smuggler", "ascii_smuggler"), ([BifidConverter()], "bifid", "bifid"), ([ColumnarTranspositionConverter(key="ZEBRAS")], "columnar_transposition", "columnar_transposition"), + # "disemvowel": remove all vowels ("disemvoweling"), a comment-moderation technique + # popularized on the Making Light blog (https://nielsenhayden.com/makinglight/). + ([SearchReplaceConverter(pattern="[AEIOUaeiou]", replace="")], "disemvowel", "disemvowel"), ] # These are the same as Garak encoding attacks diff --git a/tests/unit/scenario/garak/test_disemvowel_technique.py b/tests/unit/scenario/garak/test_disemvowel_technique.py new file mode 100644 index 0000000000..1adf6eb999 --- /dev/null +++ b/tests/unit/scenario/garak/test_disemvowel_technique.py @@ -0,0 +1,11 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT license. + +from pyrit.converter import SearchReplaceConverter + + +async def test_disemvowel_technique_removes_vowels(): + """The disemvowel Encoding technique (a SearchReplaceConverter config) strips ASCII vowels.""" + converter = SearchReplaceConverter(pattern="[AEIOUaeiou]", replace="") + result = await converter.convert_async(prompt="Hello World") + assert result.output_text == "Hll Wrld" diff --git a/tests/unit/scenario/garak/test_encoding.py b/tests/unit/scenario/garak/test_encoding.py index 5e4bd78538..b3db492701 100644 --- a/tests/unit/scenario/garak/test_encoding.py +++ b/tests/unit/scenario/garak/test_encoding.py @@ -253,13 +253,14 @@ def test_default_aggregate_curates_representative_subset(self): } all_names = {t.value for t in EncodingTechnique.get_all_techniques()} assert default_names < all_names - assert len(all_names) == 19 + assert len(all_names) == 20 # The niche/lossy schemes stay ALL-only. assert all_names - default_names == { "braille", "ecoji", "zalgo", "ascii_smuggler", + "disemvowel", "bifid", "columnar_transposition", } From 508f3356ddfb13e611bf4e660acacec0cc5c969c Mon Sep 17 00:00:00 2001 From: Roman Lutz Date: Fri, 20 Nov 2026 16:24:14 -0800 Subject: [PATCH 2/3] DOC: Update garak scanner technique list to 20 (add Columnar, Disemvowel) The Encoding scenario's ALL aggregate now has 20 techniques; the scanner guide still said 18 and ended at Bifid, omitting ColumnarTransposition (already on main) and this PR's Disemvowel. Update both the paired .py and .ipynb. Co-Authored-By: Claude Opus 4.8 --- doc/scanner/garak.ipynb | 4 ++-- doc/scanner/garak.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/scanner/garak.ipynb b/doc/scanner/garak.ipynb index a256b213da..c80945d162 100644 --- a/doc/scanner/garak.ipynb +++ b/doc/scanner/garak.ipynb @@ -303,9 +303,9 @@ "pyrit_scan run garak.encoding --target openai_chat --techniques base64 --max-total 1\n", "```\n", "\n", - "**Available techniques** (18 encodings): Base64, Base2048, Base16, Base32, ASCII85, Hex,\n", + "**Available techniques** (20 encodings): Base64, Base2048, Base16, Base32, ASCII85, Hex,\n", "QuotedPrintable, UUencode, ROT13, Braille, Atbash, MorseCode, NATO, Ecoji, Zalgo, LeetSpeak,\n", - "AsciiSmuggler, Bifid\n", + "AsciiSmuggler, Bifid, ColumnarTransposition, Disemvowel\n", "\n", "**Aggregate techniques:** `ALL` (every encoding, exhaustive) and `DEFAULT` (a broad curated subset\n", "spanning every encoding family — base-N, byte-encodings, substitution ciphers, and symbolic\n", diff --git a/doc/scanner/garak.py b/doc/scanner/garak.py index 5250721af5..17a9ebac74 100644 --- a/doc/scanner/garak.py +++ b/doc/scanner/garak.py @@ -136,9 +136,9 @@ # pyrit_scan run garak.encoding --target openai_chat --techniques base64 --max-total 1 # ``` # -# **Available techniques** (18 encodings): Base64, Base2048, Base16, Base32, ASCII85, Hex, +# **Available techniques** (20 encodings): Base64, Base2048, Base16, Base32, ASCII85, Hex, # QuotedPrintable, UUencode, ROT13, Braille, Atbash, MorseCode, NATO, Ecoji, Zalgo, LeetSpeak, -# AsciiSmuggler, Bifid +# AsciiSmuggler, Bifid, ColumnarTransposition, Disemvowel # # **Aggregate techniques:** `ALL` (every encoding, exhaustive) and `DEFAULT` (a broad curated subset # spanning every encoding family — base-N, byte-encodings, substitution ciphers, and symbolic From 02075a74c04193ff7192eccb8f63ea7dfa30a273 Mon Sep 17 00:00:00 2001 From: Roman Lutz Date: Fri, 20 Nov 2026 21:49:45 -0800 Subject: [PATCH 3/3] TEST: Cover the registered disemvowel row through scenario selection Addresses review feedback on #4449: the previous test_disemvowel_technique.py hand-built a SearchReplaceConverter and asserted its output, so it tested the converter rather than the Encoding registration (a deleted/misnamed disemvowel row would still pass). Replace it with a selection-path test in test_encoding.py that drives the scenario, asserts the raw/decode variants build, and runs the registered row's converter to confirm vowels are stripped. Co-Authored-By: Claude Opus 4.8 --- .../garak/test_disemvowel_technique.py | 11 ---- tests/unit/scenario/garak/test_encoding.py | 56 ++++++++++++++++++- 2 files changed, 55 insertions(+), 12 deletions(-) delete mode 100644 tests/unit/scenario/garak/test_disemvowel_technique.py diff --git a/tests/unit/scenario/garak/test_disemvowel_technique.py b/tests/unit/scenario/garak/test_disemvowel_technique.py deleted file mode 100644 index 1adf6eb999..0000000000 --- a/tests/unit/scenario/garak/test_disemvowel_technique.py +++ /dev/null @@ -1,11 +0,0 @@ -# Copyright (c) Microsoft Corporation. -# Licensed under the MIT license. - -from pyrit.converter import SearchReplaceConverter - - -async def test_disemvowel_technique_removes_vowels(): - """The disemvowel Encoding technique (a SearchReplaceConverter config) strips ASCII vowels.""" - converter = SearchReplaceConverter(pattern="[AEIOUaeiou]", replace="") - result = await converter.convert_async(prompt="Hello World") - assert result.output_text == "Hll Wrld" diff --git a/tests/unit/scenario/garak/test_encoding.py b/tests/unit/scenario/garak/test_encoding.py index b3db492701..7b29dd4e88 100644 --- a/tests/unit/scenario/garak/test_encoding.py +++ b/tests/unit/scenario/garak/test_encoding.py @@ -7,7 +7,12 @@ import pytest -from pyrit.converter import AskToDecodeConverter, Base64Converter, ColumnarTranspositionConverter +from pyrit.converter import ( + AskToDecodeConverter, + Base64Converter, + ColumnarTranspositionConverter, + SearchReplaceConverter, +) from pyrit.executor.attack import PromptSendingAttack from pyrit.models import AttackSeedGroup, ComponentIdentifier, DatasetFetchPolicy, SeedObjective, SeedPrompt from pyrit.prompt_target import PromptTarget @@ -345,6 +350,55 @@ async def test_base64_trimmed_to_two_variants( # The trimmed variants must not appear. assert not any("standard" in n or "b2a" in n for n in names) + async def test_disemvowel_technique_builds_registered_row( + self, mock_objective_target, mock_objective_scorer, mock_attack_seed_groups, mock_dataset_config + ): + """Selecting Disemvowel must register a row whose converter strips vowels. + + This exercises the registered ``disemvowel`` row end to end (not a hand-built converter), so a + deleted or misnamed row in ``_converter_variants()`` is caught: such a regression leaves the + enum intact while the technique builds no attacks. + """ + from unittest.mock import patch + + with patch.object( + Encoding, + "_resolve_seed_groups_by_dataset_async", + new_callable=AsyncMock, + return_value={"memory": mock_attack_seed_groups}, + ): + scenario = Encoding(objective_scorer=mock_objective_scorer) + scenario.set_params_from_args( + args={ + "objective_target": mock_objective_target, + "dataset_config": mock_dataset_config, + "scenario_techniques": [EncodingTechnique.Disemvowel], + } + ) + await scenario.initialize_async() + + attacks = scenario._get_converter_attacks( + context=scenario._build_scenario_context(seed_groups_by_dataset={"memory": mock_attack_seed_groups}) + ) + + assert attacks, "disemvowel technique built no attacks" + assert all(aa.display_group == "disemvowel" for aa in attacks) + names = {aa.atomic_attack_name for aa in attacks} + assert "disemvowel_raw" in names, "missing raw variant" + assert any(n != "disemvowel_raw" for n in names), "missing decode variant" + + # The registered row's converter actually strips vowels. + raw = next(aa for aa in attacks if aa.atomic_attack_name == "disemvowel_raw") + row_converters = [ + conv + for config in raw.attack_technique.attack.get_request_converters() + for conv in config.converters + if isinstance(conv, SearchReplaceConverter) + ] + assert row_converters, "disemvowel row applies no SearchReplaceConverter" + result = await row_converters[0].convert_async(prompt="Hello World") + assert result.output_text == "Hll Wrld" + async def test_memory_labels_propagate_to_atomic_attacks( self, mock_objective_target, mock_objective_scorer, mock_attack_seed_groups ):