Token-Aware Formatting
Remove unnecessary whitespace, comments, or metadata. Use shorter variable names in code contexts. Avoid repeating system instructions on every turn if the provider supports prompt caching.
How It Works
The prompt is formatted to minimize token count without changing semantic meaning. Techniques include stripping redundant whitespace, abbreviating identifiers, removing boilerplate comments, and deduplicating repeated instructions.
Techniques
- Whitespace minimization: collapse multiple newlines and spaces.
- Identifier shortening: use short variable names in code sent to the model.
- Comment stripping: remove explanatory comments the model does not need.
- Instruction deduplication: cache system prompts instead of repeating them.
Trade-offs
- Pros: fast; deterministic; no extra model calls.
- Cons: can hurt readability for humans; may remove contextual cues the model uses.
When to Use
Best for code-heavy prompts where the model needs the logic, not the presentation. Less useful for natural-language tasks where tone and structure matter.
See Also
- Prompt Caching — caching is the preferred way to avoid repeating instructions.
- Signal-per-Token Optimization — token-aware formatting improves signal density.
- Model-Migration Prompt Pruning — a different kind of waste: stale instructions, not whitespace/boilerplate.
- Output Spooling to Disk — when a command cannot be told to say less, redirect it and read a slice.
Tools
- tiktoken — tokenizer for measuring the impact of formatting changes.
- OpenAI prompt caching — avoids repeating stable instructions on every turn.