Skip to content

Instantly share code, notes, and snippets.

@raeq
Created September 3, 2026 19:07
Show Gist options
  • Select an option

  • Save raeq/04f5f0b88fbe3c125350db38234636df to your computer and use it in GitHub Desktop.

Select an option

Save raeq/04f5f0b88fbe3c125350db38234636df to your computer and use it in GitHub Desktop.
raeq/disarm#958: benchmarks/meta composes three disarm subjects with strip_zalgo=0, which strips every diacritic — reproduction
"""benchmarks/meta composes three disarm pipelines with strip_zalgo=0, which strips every diacritic.
disarm documents max_marks=0 as "strip all combining marks" (docs/api/transforms.md:
strip_zalgo("café", max_marks=0) == "cafe"), and None as off. The composed subjects in
benchmarks/meta/subjects.py pass 0. Run from a disarm checkout that has benchmarks/meta,
with disarm importable. Expected output on disarm 0.15.0 at da174c83:
disarm 0.15.0
TextPipeline(strip_zalgo=None) steps=[] 'Čeština, naïve café'
TextPipeline(strip_zalgo=0 ) steps=[('strip_zalgo', '0')] 'Cestina, naive cafe'
TextPipeline(strip_zalgo=3 ) steps=[('strip_zalgo', '3')] 'Čeština, naïve café'
strip_zalgo('Čeština') 'Čeština'
strip_zalgo('Čeština', max_marks=0) 'Cestina'
is_zalgo('Čeština') False
disarm-composed:prompt-hygiene strip_zalgo=0 'cestina, naive cafe' (strip_accents declared: expected to lose accents)
disarm-composed:retrieval-key strip_zalgo=0 'cestina, naive cafe' (strip_accents declared: expected to lose accents)
disarm-composed:review-display strip_zalgo=0 'Cestina, naive cafe' (no strip_accents declared: must not lose accents)
review-display with strip_zalgo=None 'Čeština, naïve café'
review-display on 100 JailbreakBench prompts: altered 88 with strip_zalgo=0, 0 with strip_zalgo=None
"""
from __future__ import annotations
import json
import os
import sys
sys.path.insert(0, os.getcwd())
import disarm # noqa: E402
from benchmarks.meta import subjects as sm # noqa: E402
from benchmarks.meta.subjects import Role # noqa: E402
SAMPLE = "Čeština, naïve café"
def main() -> None:
print("disarm", disarm.__version__)
for z in (None, 0, 3):
p = disarm.TextPipeline(strip_zalgo=z)
print(f"TextPipeline(strip_zalgo={z!r:4}) steps={p.steps!s:28} {p(SAMPLE)!r}")
print(f"strip_zalgo('Čeština') {disarm.strip_zalgo('Čeština')!r}")
print(f"strip_zalgo('Čeština', max_marks=0) {disarm.strip_zalgo('Čeština', max_marks=0)!r}")
print(f"is_zalgo('Čeština') {disarm.is_zalgo('Čeština')}")
review = None
for s in sm.all_subjects():
if not s.info.name.startswith("disarm-composed"):
continue
fn = next(iter(s.role(Role.SANITIZER).values()))
steps = type(s).STEPS
note = (
"(strip_accents declared: expected to lose accents)"
if steps.get("strip_accents")
else "(no strip_accents declared: must not lose accents)"
)
print(f"{s.info.name:32} strip_zalgo={steps.get('strip_zalgo')!r} {fn(SAMPLE)!r} {note}")
if s.info.name.endswith("review-display"):
review = (s, steps)
assert review is not None
s, steps = review
fixed = dict(steps)
fixed["strip_zalgo"] = None
fixed_fn = disarm.TextPipeline(**fixed)
print(f"review-display with strip_zalgo=None {fixed_fn(SAMPLE)!r}")
cache = os.environ.get("DISARM_META_CACHE", "/tmp/disarm_meta_cache")
path = os.path.join(cache, "jailbreakbench-prs-gpt4.json")
if os.path.exists(path):
with open(path, encoding="utf-8") as fh:
prompts = [r["prompt"] for r in json.load(fh)["jailbreaks"] if r.get("prompt")]
as_is = next(iter(s.role(Role.SANITIZER).values()))
print(
f"review-display on {len(prompts)} JailbreakBench prompts: altered "
f"{sum(1 for t in prompts if as_is(t) != t)} with strip_zalgo=0, "
f"{sum(1 for t in prompts if fixed_fn(t) != t)} with strip_zalgo=None"
)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment