smallwords
smallwords is a tiny Python package for controlled-vocabulary prompting plus
portable output resources. It keeps one wordlist at the center of the workflow
so prompt text, GBNF, JSON Schema, and post-generation validation all stay in
sync.
The package ships with a small set of bundled wordlists: direct source-backed
lists such as moby_898, basic_850, and special_english_1475, plus three
intentionally themed remixes. Most built-ins also allow slight family variants
such as go, goes, and going; Caveman uses only its listed forms.
It supports Python 3.10 and newer.
The hosted API-and-examples docs live at
cmccomb.github.io/smallwords.
See the Wordlists in Action
This paired example starts with the opening sentence and a compressed later
line from the familiar missile-guidance monologue,
then asks for six controlled-vocabulary versions.
The six rewrites below are unedited local model outputs from October 15,
2026. The runs used
ibm-granite/granite-4.2-8b-GGUF through llama-server from
llama.cpp.
Each rewrite used generated GBNF from a task-focused subset of the named
preset. The Simple run adds only missile, which now appears in the source
passage, because moby_898 does not contain it. Every constrained result also
passes the same output-shape check against its full validation wordlist.
| Mode | Model output |
|---|---|
| Original | “The missile knows where it is at all times. By subtracting where it is from where it isn't, or where it isn't from where it is, it obtains a difference, or deviation.” |
Simple (moby_898 + missile) |
“The missile knows where it is at all times. It knows where it should be next. The difference tells it how far to move.” |
Caveman (caveman_898) |
“Rock know where it be now. Rock know where it should be. Rock know how far it must go.” |
Basic English (basic_850) |
“The thing has knowledge of where the thing is now. The thing is to be at the other place. The distance from here to there is how far to move.” |
Special English (special_english_1475) |
“The missile knows where it is at all times. It should be at the second place. The distance tells how far to move from here to there.” |
Pirate (pirate_898) |
“The ship knows where it is now. The crew knows where the ship should be. The difference tells the crew which way to sail.” |
Cowboy (cowboy_898) |
“The cowboy knows where the cattle are now. The ranch is where the cattle should be. The difference tells the cowboy which way to ride.” |
The focused subsets keep the generated grammar compact for a specific task;
they add no words outside the underlying presets except the explicit missile
allowance in Simple. The themed prompts use a rock, ship, or cattle as an
analogy. Each rewrite now says who knows the current place, then explains the
target place and the difference between them.
Installation
pip install smallwords
For local development, create and activate a virtualenv first:
python -m venv .venv
source .venv/bin/activate
python -m pip install -e ".[dev]"
Quick Start
from smallwords import OutputResources, OutputShape, allow_input_words
from smallwords.prompts import build_prompt
shape = OutputShape(max_words_per_line=24, max_lines=1)
spec = allow_input_words("basic_850", "bridge")
resources = OutputResources.from_wordlist(spec, shape=shape)
prompt = build_prompt("explain", "How does a bridge work?", wordlist=spec)
schema = resources.json_schema(key="answer", title="bridge_explanation")
text = "A bridge is a structure that helps people and things move across a river or a deep place."
result = resources.validate(text)
assert result.valid, result.issues
The contrast is the point. build_prompt(...) is the soft instruction layer.
OutputResources gives you the matching hard constraints in both GBNF and JSON
Schema form. resources.validate(...) checks a response against the same
vocabulary and output shape. The older is_compliant(...) helper remains a
vocabulary-only check; it does not check punctuation or output shape.
Run the complete offline example without a model server:
python examples/offline_quickstart.py
If you want the model to be able to repeat an essential topic term such as
bridge, pass just that term to allow_input_words(...). Passing an entire
technical passage will also allow every technical word in it.
allow_input_words(...) extracts lowercase runs of Unicode letters and
combining marks between delimiters. It keeps café and an unspaced 東京 run
intact, but it does not perform language-specific word segmentation or
inflection. Unicode spellings are matched exactly after lowercasing; for
example, precomposed é and e followed by a combining accent remain
distinct. Explicit WordlistSpec literals use the same exact-match policy.
For meaning-sensitive rewrites, make sure the focused vocabulary can express each fact that must survive, including negation, causes, and time order. Vocabulary and shape validation checks the output contract; it does not assess whether a rewrite preserves the source meaning.
Built-In Wordlists
moby_898: the full normalized alpha-only Moby Words II frequency listbasic_850: Charles Ogden's Basic English 850special_english_1475: Voice of America Special Englishcaveman_898: a 355-word, surface-onlymoby_898remix with short, chiefly Germanic-rooted wordscowboy_898: a size-neutralmoby_898remix for ranch and trail storiespirate_898: a size-neutralmoby_898remix for playful sea stories
The bundled text files live in src/smallwords/data/. moby_898,
basic_850, and special_english_1475 are direct source-backed lists.
caveman_898, cowboy_898, and pirate_898 are derived from moby_898.
The caveman preset now keeps 355 one-syllable words with chiefly Germanic roots,
such as bone, rock, stone, spear, ash, and wolf. It drops most
obvious Latin, Greek, and French borrowings, as well as words with unclear
roots. Eight plain, useful exceptions remain: fur, leach, oil, rock,
tent, wall, war, and plant. Its public name still ends in 898 because
it starts from moby_898; it no longer has 898 entries. The
full removal list records all 543 words
removed from the former preset. The
curated vocabulary
is the source of truth. Pronunciations were screened with
CMUdict, and word origins with a
Wiktionary-derived classification
and Wiktionary spot checks.
Etymologies can be disputed, so this is a deliberately conservative voice
preset.
The cowboy and pirate presets each swap 40 abstract base words for themed terms
and everyday pronouns missing from moby_898. Their style_hint values guide
build_prompt(...); the generated grammar and schema still enforce the
vocabulary and output shape. These are playful voices, not historical dialect
models. The terms draw on National Park Service cowboy history
and Royal Museums Greenwich's pirate word guide.
Run python examples/themed_presets.py to inspect both prompts and validate
sample lines without a model server. The remixes live in
src/smallwords/themes/. Use remix_wordlist(...) to build your own.
Examples
Start with the offline quick start above. For live-model examples, see the repository's
examples/README.md
for the runnable examples. The missile contrast, pirate greeting, and technical
rewrite call a live llama-server model with a prompt plus generated grammar.
Development
Run these commands from an activated virtualenv:
python -m pip install -e ".[dev]"
python -m ruff check .
python -m ruff format --check .
python -m pytest
python scripts/check_documentation.py
python -m sphinx -W --keep-going -b html docs docs/_build/html
python -m build
python -m twine check --strict dist/*
CI runs linting, tests, the documentation policy check, a >=90% coverage
gate, a Sphinx docs build, and a package build on GitHub Actions.
For release steps and Trusted Publishing setup, see
RELEASING.md.
Metadata
Release files for smallwords 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| smallwords-0.2.1.tar.gz | 56.3 kB | With provenance | Details for smallwords-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| smallwords-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for smallwords-0.2.1-py3-none-any.whl |
Total release size: 98.8 kB
Release files / smallwords-0.2.1.tar.gz
| Download URL | smallwords-0.2.1.tar.gz |
|---|---|
| Size | 56.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d0bdc0cbad3dc6355a055eb3dc33710f2e5fc2474134c55520e8e55e52fc221f
|
|
BLAKE2b-256 checksum How to use checksums |
fae30a503157324714373537ad950a98e9cb814c79d81822fe0db087792a144a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.
Transparency logRelease files / smallwords-0.2.1-py3-none-any.whl
| Download URL | smallwords-0.2.1-py3-none-any.whl |
|---|---|
| Size | 42.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4e0fd2bd81a69ea92eb398d6a0bf7909525bbf1321d2c99c31104d803b3f1f8e
|
|
BLAKE2b-256 checksum How to use checksums |
0213722285b68abc526f395195ad9af6e2ab9c91f3bfa8839664e466bec0d560
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.
Transparency logSecurity for smallwords 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for smallwords-0.2.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.