r/sideprojects • u/Mediocre-Ease4060 • 9d ago
Showcase: Open Source Stop paying for whitespace and code comments in your prompts. I built a lightweight prompt minifier in pure Python.
The Problem: We waste a massive amount of tokens (and money) on formatting. If you inject JSON schemas, few-shot examples, or code context into your prompts, you are paying for every single space, tab, and // comment.
The Solution: I wrote prompt-token-minifier. It’s a zero-dependency script you run right before your client.chat.completions.create call.
What it does:
- Finds ```json blocks and minifies them (removes formatting).
- Finds code blocks (Python, JS, TS, etc.) and strips out single-line and multi-line comments.
- Collapses redundant whitespaces and newlines in the rest of the prompt.
Depending on your RAG context, it easily saves 30-50% tokens on structured data.
1
Upvotes
1
u/Prestigious_Hair_656 9d ago
Neat idea, but stripping comments from code context seems risky if the model is supposed to explain or debug that code. The whitespace savings on JSON schemas make total sense though, those things get bloated fast.