A lightweight Python toolkit for cleaning and preparing text before sending it to any LLM (GPT, Claude, Gemini, etc.)
Every AI developer copy-pastes these utilities across projects. Now you don't have to.
pip install promptkit
| Function | What it does |
|---|---|
clean(text) |
Removes extra spaces, repeated punctuation |
truncate_tokens(text, max_words) |
Trims text to stay within token limits |
remove_pii(text) |
Masks emails, phone numbers, URLs |
format_prompt(template, **kwargs) |
Safely fills prompt templates |
word_count(text) |
Returns word count of a string |
from promptkit import clean, truncate_tokens, remove_pii, format_prompt, word_count
# Clean messy input
clean(" Hello!!! World??? ")
# → "Hello! World?"
# Truncate to token budget
truncate_tokens("one two three four five", max_words=3)
# → "one two three..."
# Remove sensitive info before sending to external APIs
remove_pii("My email is john@gmail.com and number is 9876543210")
# → "My email is [EMAIL] and number is [PHONE]"
# Fill prompt templates safely
format_prompt("Summarize: {text}", text="Hello world")
# → "Summarize: Hello world"
# Quick word count
word_count("Hello world foo bar")
# → 4- ✅ Zero dependencies — pure Python
- ✅ Works with any LLM — OpenAI, Anthropic, Google, local models
- ✅ PII removal keeps your users' data safe
- ✅ Token truncation saves API costs
MIT — free to use, modify, and distribute.