Skip to main content

Monsters for your language games.

Project description

     .─') _                                       .─') _                  
    (  OO) )                                     ( OO ) )            
  ░██████  ░██ ░██   ░██               ░██       ░██ ░██                                 
 ░██   ░██ ░██       ░██               ░██       ░██                                     
░██        ░██ ░██░████████  ░███████ ░████████  ░██ ░██░████████   ░████████ ░███████  
░██  █████ ░██ ░██   ░██    ░██('─.░██ ░██    ░██ ░██ ░██░██    ░██ ░██.─')░██ ░██        
░██     ██ ░██ ░██   ░██    ░██( OO ) ╱░██    ░██ ░██ ░██░██    ░██ ░██(OO)░██ ░███████  
  ░██  ░███ ░██ ░██   ░██   ░██    ░██ ░██    ░██ ░██ ░██░██    ░██ ░██  o░███      ░██ 
  ░█████░█ ░██ ░██   ░████   ░███████  ░██    ░██ ░██ ░██░██    ░██  ░█████░██ ░███████  
                                                                    ░██            
                                                                ░███████             

                        Every language game breeds monsters.

Glitchlings are utilities for corrupting the text inputs to your language models in deterministic, linguistically principled ways.
Each embodies a different way that documents can be compromised in the wild.

If reinforcement learning environments are games, then Glitchlings are enemies to breathe new life into old challenges.

They do this by breaking surface patterns in the input while keeping the target output intact.

Some Glitchlings are petty nuisances. Some Glitchlings are eldritch horrors.
Together, they create truly nightmarish scenarios for your language models.

After all, what good is general intelligence if it can't handle a little chaos?

-The Curator

Quickstart

pip install -U glitchlings

Glitchlings requires Python 3.10 or newer.

from glitchlings import Gaggle, SAMPLE_TEXT, Typogre, Mim1c, Reduple, Rushmore

gaggle = Gaggle([
    Typogre(rate=0.03),
    Mim1c(rate=0.02),
    Reduple(seed=404),
    Rushmore(rate=0.02),
])

print(gaggle(SAMPLE_TEXT))

Onҽ m‎ھ‎rning, wһen Gregor Samƽa woke from trouble𝐝 𝑑reams, he found himself transformed in his bed into a horrible vermin‎٠‎ He l lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightlh domed and divided by arches ino stiff sections. The bedding was adly able to cover it and and seemed ready to slide off any moment. His many legxs, pitifully thin compared with the size of the the rest of him, waved about helplessly ashe looked looked.

Consult the Glitchlings Usage Guide for end-to-end instructions spanning the Python API, CLI, HuggingFace and Prime Intellect integrations, and the autodetected Rust pipeline (enabled whenever the extension is present).

Motivation

If your model performs well on a particular task, but not when Glitchlings are present, it's a sign that it hasn't actually generalized to the problem.

Conversely, training a model to perform well in the presence of the types of perturbations introduced by Glitchlings should help it generalize better.

Your First Battle

Summon your chosen Glitchling (or a few, if ya nasty) and call it on your text or slot it into Dataset.map(...), supplying a seed if desired. Glitchlings are standard Python classes, so you can instantiate them with whatever parameters fit your scenario:

from glitchlings import Gaggle, Typogre, Mim1c

custom_typogre = Typogre(rate=0.1)
selective_mimic = Mim1c(rate=0.05, classes=["LATIN", "GREEK"])

gaggle = Gaggle([custom_typogre, selective_mimic], seed=99)
print(gaggle("Summoned heroes do not fear the glitch."))

Calling a Glitchling on a str transparently calls .corrupt(str, ...) -> str. This means that as long as your glitchlings get along logically, they play nicely with one another.

When summoned as or gathered into a Gaggle, the Glitchlings will automatically order themselves into attack waves, based on the scope of the change they make:

  1. Document
  2. Paragraph
  3. Sentence
  4. Word
  5. Character

They're horrible little gremlins, but they're not unreasonable.

Command-Line Interface (CLI)

Keyboard warriors can challenge them directly via the glitchlings command:

# Discover which glitchlings are currently on the loose.
glitchlings --list
   Typogre — scope: Character, order: early
     Mim1c — scope: Character, order: last
  Jargoyle — scope: Word, order: normal
     Adjax — scope: Word, order: normal
   Reduple — scope: Word, order: normal
  Rushmore — scope: Word, order: normal
  Redactyl — scope: Word, order: normal
Scannequin — scope: Character, order: late
    Zeedub — scope: Character, order: last
# Review the full CLI contract.
glitchlings --help
usage: glitchlings [-h] [-g SPEC] [-s SEED] [-f FILE] [--sample] [--diff]
                   [--list] [-c CONFIG]
                   [text]

Summon glitchlings to corrupt text. Provide input text as an argument, via
--file, or pipe it on stdin.

positional arguments:
  text                  Text to corrupt. If omitted, stdin is used or --sample
                        provides fallback text.

options:
  -h, --help            show this help message and exit
  -g SPEC, --glitchling SPEC
                        Glitchling to apply, optionally with parameters like
                        Typogre(rate=0.05). Repeat for multiples; defaults to
                        all built-ins.
  -s SEED, --seed SEED  Seed controlling deterministic corruption order
                        (default: 151).
  -f FILE, --file FILE  Read input text from a file instead of the command
                        line argument.
  --sample              Use the included SAMPLE_TEXT when no other input is
                        provided.
  --diff                Show a unified diff between the original and corrupted
                        text.
  --list                List available glitchlings and exit.
  -c CONFIG, --config CONFIG
                        Load glitchlings from a YAML configuration file.

Run python docs/build_cli_reference.py whenever you tweak the CLI so the README stays in sync with the actual output. The script executes the commands above and replaces the block between the markers automatically.

Prefer inline tweaks? You can still configure glitchlings directly in the shell:

# Run Typogre against the contents of a file and inspect the diff.
glitchlings -g typogre --file documents/report.txt --diff

# Configure glitchlings inline by passing keyword arguments.
glitchlings -g "Typogre(rate=0.05)" "Ghouls just wanna have fun"

# Pipe text straight into the CLI for an on-the-fly corruption.
echo "Beware LLM-written flavor-text" | glitchlings -g mim1c

# Load a roster from a YAML attack configuration.
glitchlings --config experiments/chaos.yaml "Let slips the glitchlings of war"

Attack configurations live in plain YAML files so you can version-control experiments without touching code:

# experiments/chaos.yaml
seed: 31337
glitchlings:
  - name: Typogre
    rate: 0.04
  - "Rushmore(rate=0.12, unweighted=True)"
  - name: Zeedub
    parameters:
      rate: 0.02
      characters: ["\u200b", "\u2060"]

Pass the file to glitchlings --config or load it from Python with glitchlings.load_attack_config and glitchlings.build_gaggle.

Development

Follow the development setup guide for editable installs, automated tests, and tips on enabling the Rust pipeline while you hack on new glitchlings.

Starter 'lings

For maintainability reasons, all Glitchling have consented to be given nicknames once they're in your care. See the Monster Manual for a complete bestiary.

Typogre

What a nice word, would be a shame if something happened to it.

Fatfinger. Typogre introduces character-level errors (duplicating, dropping, adding, or swapping) based on the layout of a keyboard (QWERTY by default, with Dvorak and Colemak variants built-in).

Args

  • rate (float): The maximum number of edits to make as a percentage of the length (default: 0.02, 2%).
  • keyboard (str): Keyboard layout key-neighbor map to use (default: "CURATOR_QWERTY"; also accepts "QWERTY", "DVORAK", "COLEMAK", and "AZERTY").
  • seed (int): The random seed for reproducibility (default: 151).

Mim1c

Wait, was that...?

Confusion. Mim1c replaces non-space characters with Unicode Confusables, characters that are distinct but would not usually confuse a human reader.

Args

  • rate (float): The maximum proportion of characters to replace (default: 0.02, 2%).
  • classes (list[str] | "all"): Restrict replacements to these Unicode script classes (default: ["LATIN", "GREEK", "CYRILLIC"]).
  • banned_characters (Collection[str]): Characters that must never appear as replacements (default: none).
  • seed (int): The random seed for reproducibility (default: 151).

Scannequin

How can a computer need reading glasses?

OCR Artifacts. Scannequin mimics optical character recognition errors by swapping visually similar character sequences (like rn↔m, cl↔d, O↔0, l/I/1).

Args

  • rate (float): The maximum proportion of eligible confusion spans to replace (default: 0.02, 2%).
  • seed (int): The random seed for reproducibility (default: 151).

Zeedub

Watch your step around here.

Invisible Ink. Zeedub slips zero-width codepoints between non-space character pairs, forcing models to reason about text whose visible form masks hidden glyphs.

Args

  • rate (float): Expected number of zero-width insertions as a proportion of eligible bigrams (default: 0.02, 2%).
  • characters (Sequence[str]): Optional override for the pool of zero-width strings to inject (default: curated invisibles such as U+200B, U+200C, U+200D, U+FEFF, U+2060).
  • seed (int): The random seed for reproducibility (default: 151).

Jargoyle

Uh oh. The worst person you know just bought a thesaurus.

Sesquipedalianism. Jargoyle, the insufferable Glitchling, replaces words from selected parts of speech with synonyms at random, without regard for connotational or denotational differences.

Args

  • rate (float): The maximum proportion of words to replace (default: 0.01, 1%).
  • part_of_speech: The WordNet-style part(s) of speech to target (default: nouns). Accepts wn.NOUN, wn.VERB, wn.ADJ, wn.ADV, any iterable of those tags, or the string "any" to include them all. Vector/graph backends ignore this filter while still honouring deterministic sampling.
  • seed (int): The random seed for reproducibility (default: 151).

Reduple

Did you say that or did I?

Broken Record. Reduple stutters through text by randomly reduplicating words. Like a nervous speaker, it creates natural repetitions that test a model's ability to handle redundancy without losing the thread.

Args

  • rate (float): The maximum proportion of words to reduplicate (default: 0.01, 1%).
  • unweighted (bool): Sample words uniformly instead of favouring shorter tokens (default: False).
  • seed (int): The random seed for reproducibility (default: 151).

Rushmore

I accidentally an entire word.

Hasty Omission. The evil (?) twin of reduple, Rushmore moves with such frantic speed that it causes words to simply vanish from existence as it passes.

Args

  • rate (float): The maximum proportion of words to delete (default: 0.01, 1%).
  • unweighted (bool): Sample words uniformly instead of favouring shorter tokens (default: False).
  • seed (int): The random seed for reproducibility (default: 151).

Adjax

Keep your hands and punctuation where I can see them.

Perfect Shuffle. Adjax trades the cores of neighbouring words while leaving punctuation, casing, and surrounding whitespace untouched, turning fluent prose into locally scrambled tongue-twisters.

Args

  • rate (float): Probability that each adjacent pair swaps cores (default: 0.5, 50%).
  • swap_rate (float): Alias for rate, retained for backward compatibility.
  • seed (int): The random seed for reproducibility (default: 151).

Redactyl

Oops, that was my black highlighter.

FOIA Reply. Redactyl obscures random words in your document like an NSA analyst with a bad sense of humor.

Args

  • replacement_char (str): The character to use for redaction (default: FULL_BLOCK).
  • rate (float): The maximum proportion of words to redact (default: 0.025, 2.5%).
  • merge_adjacent (bool): Whether to redact the space between adjacent redacted words (default: False).
  • unweighted (bool): Sample words uniformly instead of biasing toward longer tokens (default: False).
  • seed (int): The random seed for reproducibility (default: 151).

Field Report: Uncontained Specimens

Containment procedures pending

  • ekkokin substitutes words with homophones (phonetic equivalents).
  • nylingual backtranslates portions of text.
  • glothopper introduces code-switching effects, blending languages or dialects.
  • palimpsest rewrites, but leaves accidental traces of the past.
  • vesuvius is an apocryphal Glitchling with ties to [Nosy, aren't we? -The Curator]

Apocrypha

Cave paintings and oral tradition contain many depictions of strange, otherworldly Glitchlings.
These Apocryphal Glitchling are said to possess unique abilities or behaviors.
If you encounter one of these elusive beings, please document your findings and share them with The Curator.

Ensuring Reproducible Corruption

Every Glitchling should own its own independent random.Random instance. That means:

  • No random.seed(...) calls touch Python's global RNG.
  • Supplying a seed when you construct a Glitchling (or when you summon(...)) makes its behavior reproducible.
  • Re-running a Gaggle with the same master seed and the same input text (and same external data!) yields identical corruption output.
  • Corruption functions are written to accept an rng parameter internally so that all randomness is centralized and testable.

At Wits' End?

If you're trying to add a new glitchling and can't seem to make it deterministic, here are some places to look for determinism-breaking code:

  1. Search for any direct calls to random.choice, random.shuffle, or set(...) ordering without going through the provided rng.
  2. Ensure you sort collections before shuffling or sampling.
  3. Make sure indices are chosen from a stable reference (e.g., original text) when applying length‑changing edits.
  4. Make sure there are enough sort keys to maintain stability.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

glitchlings-0.4.2.tar.gz (96.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

glitchlings-0.4.2-cp312-cp312-win_amd64.whl (866.9 kB view details)

Uploaded CPython 3.12Windows x86-64

glitchlings-0.4.2-cp312-cp312-manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

glitchlings-0.4.2-cp312-cp312-macosx_11_0_universal2.whl (974.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ universal2 (ARM64, x86-64)

glitchlings-0.4.2-cp311-cp311-manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

glitchlings-0.4.2-cp311-cp311-macosx_11_0_universal2.whl (975.0 kB view details)

Uploaded CPython 3.11macOS 11.0+ universal2 (ARM64, x86-64)

glitchlings-0.4.2-cp310-cp310-manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

glitchlings-0.4.2-cp310-cp310-macosx_11_0_universal2.whl (975.1 kB view details)

Uploaded CPython 3.10macOS 11.0+ universal2 (ARM64, x86-64)

File details

Details for the file glitchlings-0.4.2.tar.gz.

File metadata

  • Download URL: glitchlings-0.4.2.tar.gz
  • Upload date:
  • Size: 96.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for glitchlings-0.4.2.tar.gz
Algorithm Hash digest
SHA256 e4eae5eb48a217fa6cd704246af44fcffb1a6386e0e7b4990a952e772525920c
MD5 0381743775787005f8305b9f036f2232
BLAKE2b-256 61c775caf098bcd71653e06179e62d622ad25c4b14615d6766385a22cfc0ec7a

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.4.2.tar.gz:

Publisher: publish.yml on osoleve/glitchlings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file glitchlings-0.4.2-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: glitchlings-0.4.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 866.9 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for glitchlings-0.4.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 852ed922e70f01474132973344d3ecd25ee22fd1fa668d2e9db6d108a809e351
MD5 4646cf036bcd3a4968ed16d7d04aa72d
BLAKE2b-256 116df66d46cf45febc9be31a93025f15e383b71f2433843f3c733f8e999a5217

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.4.2-cp312-cp312-win_amd64.whl:

Publisher: publish.yml on osoleve/glitchlings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file glitchlings-0.4.2-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for glitchlings-0.4.2-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d3e27eccb2a2d204f718643e7f50ce193a91f307efe4c8c02520f0b8adbbe9c9
MD5 166cd4f14e364b00a62320a429744618
BLAKE2b-256 3c146534d3ec2131b3852ecfc506c5ce42223d015ca0876574a61f07675be438

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.4.2-cp312-cp312-manylinux_2_28_x86_64.whl:

Publisher: publish.yml on osoleve/glitchlings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file glitchlings-0.4.2-cp312-cp312-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for glitchlings-0.4.2-cp312-cp312-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 15ea785d2611bd48681555087e522ec7d1f873284339d54feda1c23585a3e7ff
MD5 aa22be831382b96c39445ad16baec489
BLAKE2b-256 d89112c4ff6ac4a964e3cd347f5d5c9fba011b9f30d08900003064303efe7fb7

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.4.2-cp312-cp312-macosx_11_0_universal2.whl:

Publisher: publish.yml on osoleve/glitchlings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file glitchlings-0.4.2-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for glitchlings-0.4.2-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5e7bab5e9193b4e63d9881d503158e096c61c3907e15ec1e787b9ed196668123
MD5 1be6260f3586c989705efc47be4ab0ca
BLAKE2b-256 6f6d947cfbad8f29f4c459d987e54712dd5f147a852a543f09bff33c0b24ce32

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.4.2-cp311-cp311-manylinux_2_28_x86_64.whl:

Publisher: publish.yml on osoleve/glitchlings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file glitchlings-0.4.2-cp311-cp311-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for glitchlings-0.4.2-cp311-cp311-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 d8c07fde11ea18b8ea6cb255ebd5749985e18a184b692107093820a8bee3203b
MD5 54eba31970ed2608ebfb829ce46c5933
BLAKE2b-256 d692e615ef17680afd841ff8068c7de286ebe109889b687dbc25d0b9baeefed2

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.4.2-cp311-cp311-macosx_11_0_universal2.whl:

Publisher: publish.yml on osoleve/glitchlings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file glitchlings-0.4.2-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for glitchlings-0.4.2-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b10a29b8adffb8e76938f8a98ccfacc8b84aeea29fb72f30ddf1450fda1c7d4c
MD5 f7286cfe2debfdc2399d8c0ac0b10d24
BLAKE2b-256 321cdb0732a1ff7de942a46f7c3d5bf3ea37ae5e96dd00224da2035e98a41bd3

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.4.2-cp310-cp310-manylinux_2_28_x86_64.whl:

Publisher: publish.yml on osoleve/glitchlings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file glitchlings-0.4.2-cp310-cp310-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for glitchlings-0.4.2-cp310-cp310-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 4ba86811618cc8290608ca187089d11d7b2fb1d526871de612b318fb9d792e8f
MD5 ee291c75e6f485ab024c72e484d078e1
BLAKE2b-256 ae520316146399ef7c8a557781db4f8ac45e6f5868aebf873fc5c96de3183268

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.4.2-cp310-cp310-macosx_11_0_universal2.whl:

Publisher: publish.yml on osoleve/glitchlings

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page