Skip to main content

Monsters for your language games.

Project description

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

                        Every language game breeds monsters.

Python Versions PyPI version Wheel Linting and Typing
Entropy Budget Chaos Charm
Lore Compliance

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

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.

Quickstart

pip install -U glitchlings

The fastest way to get started is to ask my assistant, Auggie, to prepare a custom mix of glitchlings for you:

from glitchlings import Auggie, SAMPLE_TEXT

auggie = (
    Auggie(seed=404)
    .typo(rate=0.015)
    .confusable(rate=0.01)
    .homophone(rate=0.02)
)

print(auggie(SAMPLE_TEXT))

One morning, when Gregor Samsa woke from troubld dreams, he found himself transformed in his bed into a horible vermin. He layed on his armour-like back, and if he lifted his head a little he could see his brown belly, slightly domed and divided by arches into stiff sections. The bedding was hardly able to cover it and seemed ready to slide off any moment. His many legs, pitifully thin compared with the size of the rest of him, waved about helplessly as he looked.

You're more than welcome to summon them directly, if you're feeling brave:

from glitchlings import Gaggle, SAMPLE_TEXT, Typogre, Mim1c, Wherewolf

gaggle = Gaggle(
    [
        Typogre(rate=0.015),
        Mim1c(rate=0.01),
        Wherewolf(rate=0.02),
    ],
    seed=404
)

Consult the Glitchlings Usage Guide for end-to-end instructions spanning the Python API, CLI, and third-party integrations.

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:

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)
corrupted = gaggle("We Await Silent Tristero's Empire.")
print(corrupted)

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 (see the generated CLI reference in docs/cli.md for the full contract):

# Discover which glitchlings are currently on the loose.
glitchlings --list
 
# Review the full CLI contract.
glitchlings --help
 
# Run Typogre against the contents of a file and inspect the diff.
glitchlings -g typogre --input-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

# Emit an Attack summary with metrics and counts.
glitchlings --attack --sample

# Emit a full Attack report with tokens, token IDs, and metrics.
glitchlings --report --sample

Configuration Files

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

# Load a roster from a YAML attack configuration.
glitchlings --config experiments/chaos.yaml "Let slips the glitchlings of war"
# 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"]

Attack on Token

Looking to compare before/after corruption with metrics and stable seeds? Reach for the Attack helper, which bundles tokenization, metrics, and transcript batching into a single utility. It accepts plain list[str] batches, renders quick summary() reports, and can compare multiple tokenizers via Attack.compare(...) when you need a metrics matrix.

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).

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.

Hokey

She's soooooo coooool!

Passionista. Hokey gets a little excited and streeeeetches words for emphasis.

Apocryphal Glitchling contributed by Chloé Nunes

Scannequin

How can a computer need reading glasses?

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

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.

Wherewolf

Did you hear what I heard?

Echo Chamber. Wherewolf swaps words with curated homophones so the text still sounds right while the spelling drifts. Groups are normalised to prevent duplicates and casing is preserved when substitutions fire.

Jargoyle

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

Sesquipedalianism. Jargoyle insufferably replaces words with synonyms at random, without regard for connotational or denotational differences.

Rushmore

I accidentally an entire word.

Tactical Scrambler. Rushmore randomly drops, duplicates, or swaps words in the text to simulate hasty writing, editing mistakes, or transmission errors.

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.

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.10.1.tar.gz (278.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.10.1-cp313-cp313-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.13Windows x86-64

glitchlings-0.10.1-cp313-cp313-manylinux_2_28_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

glitchlings-0.10.1-cp313-cp313-macosx_11_0_universal2.whl (1.5 MB view details)

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

glitchlings-0.10.1-cp312-cp312-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.12Windows x86-64

glitchlings-0.10.1-cp312-cp312-manylinux_2_28_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

glitchlings-0.10.1-cp312-cp312-macosx_11_0_universal2.whl (1.5 MB view details)

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

glitchlings-0.10.1-cp311-cp311-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.11Windows x86-64

glitchlings-0.10.1-cp311-cp311-manylinux_2_28_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

glitchlings-0.10.1-cp311-cp311-macosx_11_0_universal2.whl (1.5 MB view details)

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

glitchlings-0.10.1-cp310-cp310-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.10Windows x86-64

glitchlings-0.10.1-cp310-cp310-manylinux_2_28_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

glitchlings-0.10.1-cp310-cp310-macosx_11_0_universal2.whl (1.5 MB view details)

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

File details

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

File metadata

  • Download URL: glitchlings-0.10.1.tar.gz
  • Upload date:
  • Size: 278.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.10.1.tar.gz
Algorithm Hash digest
SHA256 17a8cec7b3cdccdedc70657f90deb6579f8fc2b2f366c97886a3565ef04322d0
MD5 be8cf6fcf0f0a52e6eb732f46c83f685
BLAKE2b-256 6b7022932297df2bfdab4d63c188a802ab77673da38882a35607c42eeb7a0b16

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.10.1.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.10.1-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for glitchlings-0.10.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 f3baebd3d5bba090c21d7cd0befee7faa2c08fe0734b230bfd36eb66d8531aa7
MD5 d52f6278b0c0a98a5f997d622673b2f0
BLAKE2b-256 47a6eebf4d0924e10d8efadb72b23cfdbe9ff9f3a7737c74b2f51be1cd7bb97f

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.10.1-cp313-cp313-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.10.1-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for glitchlings-0.10.1-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3638f23747b83972940b7d92731ef02609a7cfca7b2b6d2bd75d354398917f3f
MD5 5cc680a327b3554a2aa1936431b82b65
BLAKE2b-256 5259dd3fc1b431c51d5eeca0b4320989a9cc5b93bd8794419563615bbb8bd91c

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.10.1-cp313-cp313-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.10.1-cp313-cp313-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for glitchlings-0.10.1-cp313-cp313-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 b99338bc04441410ceee20ed9b1bfec23e4af1cf3ef29a9d9b13166973cd065d
MD5 8930a94d559e49dc08a343ed61838c2d
BLAKE2b-256 7f776ccfd069e642fa4967703018faa910d77448d397135afc4f802a12724d1d

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.10.1-cp313-cp313-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.10.1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for glitchlings-0.10.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 630a974abde6373e4e0c5b02ae13cb8c44a71dc7a9e614aad65b29bbf490a14c
MD5 af0411f2a9a1bf9c4d5cd39084004558
BLAKE2b-256 5d3a9cffe692ca1b81aacec56270c0a8825f18809603576cc4962a110b2140b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.10.1-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.10.1-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for glitchlings-0.10.1-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 262fecb8fdf4550ab682c742380b72036607f315bdcf04ffff74db63a74f0606
MD5 0c3e81fb0bbeb378da61d3c77ed9f3e4
BLAKE2b-256 4a3ec648045e70e484a56f46bef472fb2580b8e531885e435e7bade2904dec01

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.10.1-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.10.1-cp312-cp312-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for glitchlings-0.10.1-cp312-cp312-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 1bb21ea59c3d892780ca418d0a324b718837d32452df253bcebc66396cb840e7
MD5 0b0de7cfeb0555a9bcf155f401df3ada
BLAKE2b-256 0ac32765dc23a56aa8c9b359b994209fad8ea3203aaa6e2096d1323228e501d1

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.10.1-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.10.1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for glitchlings-0.10.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 9dd5929c72886bf693bcc42a8fbfd5efc296fac9aade7960c638fc3d6af2b64e
MD5 8010c0a3c941200b2b9cb60d77833751
BLAKE2b-256 1af961fb79168d004c2f130f76c159741a538538829ee9e6f5d8f9e1b025eac6

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.10.1-cp311-cp311-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.10.1-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for glitchlings-0.10.1-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0528b8de41ae124a48739332e18253c3c810c0147d668813664d0f98c6021865
MD5 9e561ccfe1b5947336dd18c676c1448c
BLAKE2b-256 d38da5a90396d56b98797b559a0f8741ebab2713126c40df312915b3432177ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.10.1-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.10.1-cp311-cp311-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for glitchlings-0.10.1-cp311-cp311-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 551c69f99205012c8568b6a3008824d7e151b4ea6c1f0f50f86a42f742b6744d
MD5 656c7e19e0256f4fbeec04d76a668025
BLAKE2b-256 e42830f4bf36ef07298e9c5416b28f1aac95c3ea5e6d6ff2ac483a4d4aaf2620

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.10.1-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.10.1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for glitchlings-0.10.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 8753dbc9b7390001fe8c3a1f38912a5401b84a38fc91b3b3f019f75eaa585cb4
MD5 d590c644c421a677b200ed1c2e1b25cc
BLAKE2b-256 ddaba511a6a90afa6ef497386a0f4caa9ad8d6d08e10d9989a9cb0a80b0ca17c

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.10.1-cp310-cp310-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.10.1-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for glitchlings-0.10.1-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c3977ca64dc8270bda053761ad0897d2eee60ea58aad3ff4db9721dd5a5574f5
MD5 ada18db47a7705121af4966715372a62
BLAKE2b-256 a8d48804e57042543851718ce3aad5210216c8dfd531ad44bfb5f1ed92be5874

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.10.1-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.10.1-cp310-cp310-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for glitchlings-0.10.1-cp310-cp310-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 098dac5bb593be3a098448f09c37bc39c7644d9c45a179307ca956f67213f15b
MD5 1375f5e2162c0b251a40546496522a87
BLAKE2b-256 7bc833cbeae726429511d1c86afe8cda31130ac6906ed4b0890d47c281397753

See more details on using hashes here.

Provenance

The following attestation bundles were made for glitchlings-0.10.1-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