Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Prompt Token Minifier

A zero-dependency Python micro-tool to shrink your LLM prompts before sending them to the API. It saves tokens and reduces costs by:

  • Minifying JSON schemas and examples inside Markdown blocks.
  • Stripping comments (//, #, /* */) from code blocks.
  • Collapsing redundant whitespaces and newlines.

Installation

pip install prompt-token-minifier

Usage

from prompt_token_minifier import minify_prompt

raw_prompt = """
You are a helpful assistant.
    
Here is the JSON schema you must follow:

{
  "type": "object",
  "properties": {
    "name": {
      "type": "string"
    }
  }
}

And some context code:

# This function calculates the sum
def add(a, b):
    return a + b
print(minify_prompt(raw_prompt))

Output: (Saves ~40% tokens depending on formatting)

You are a helpful assistant.

Here is the JSON schema you must follow:

{"type":"object","properties":{"name":{"type":"string"}}}

And some context code:

def add(a, b):
    return a + b

About

A lightweight Python minifier that strips formatting and comments from JSON and code blocks to drastically reduce LLM prompt token costs.

Topics

Resources

Stars

8 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages