Local runtime prompt optimization and proxy engine for LLM providers.
Project description
PromptGuard Proxy
PromptGuard Proxy is a local-first runtime optimization engine that transforms prompts and returns compressed payloads plus optimization metrics.
Design Principles
- Provider-agnostic optimization: all provider payloads map to a common
PromptRequestmodel. - Compiler-like pipeline: each request is parsed, transformed, optimized, and returned as local output.
- Privacy-first runtime: local execution, local SQLite stats, no telemetry or cloud sync.
- Extensibility: plugin-style optimization passes and adapter registry for new providers.
Input Compatibility
- Anthropic payload shape
- OpenAI payload shape
- Gemini payload shape
- Groq payload shape
- OpenRouter payload shape
Architecture
- Incoming HTTP payload reaches a provider endpoint.
- Adapter parses provider payload into
PromptRequest. - Optimization pipeline executes pass chain.
- Prompt AST is generated for diagnostics and pruning support.
- Optimized request is serialized by adapter.
- Local response with compressed prompt and stats is returned.
- Statistics are persisted to SQLite and history is stored in JSONL.
Project Layout
promptguard_proxy/adapters: provider adapters (parsing, auth, serialization, response conversion only)promptguard_proxy/core: parser, models, optimizer, tokenizer, serializer, cache, plugins, statisticspromptguard_proxy/api: FastAPI app, routes, dependenciespromptguard_proxy/storage: runtime storage utilitiespromptguard_proxy/tests: unit tests
Quick Start
1. Install
pip install promptguard-proxy
2. Initialize config
promptguard init
3. Configure provider API keys
Edit promptguard.yaml and fill provider keys.
4. Start proxy
promptguard start
5. Check health
curl http://127.0.0.1:8787/health
API Endpoints
GET /healthGET /statsGET /metricsGET /providersGET /history/contextWS /dashboard/wsPOST /v1/chat/completionsPOST /v1/messagesPOST /history/memoryPOST /reload
CLI Commands
promptguard initpromptguard startpromptguard stoppromptguard statuspromptguard configpromptguard doctor
Optimization Passes (v1)
- Duplicate Removal
- Prompt Compression
- Context Pruning
- Conversation Compression
- Markdown Compression
- JSON Compression
- Log Compression
- HTML Compression
- Dead Prompt Elimination
- Greedy Token Pruning
Each pass implements:
name()description()run()rollback()statistics()estimated_savings()
Dashboard Stats Shape
GET /metrics returns:
{
"requests": 142,
"original_tokens": 294221,
"optimized_tokens": 148003,
"saved_tokens": 146218,
"saved_money": 11.82,
"compression_ratio": 50,
"provider_usage": {},
"model_usage": {},
"optimization_breakdown": {}
}
Testing
pip install -e .[dev]
pytest
Publishing
Build and validate the distributions before uploading them:
python -m build
python -m twine check dist/*
python -m twine upload dist/*
Notes
- This repository intentionally does not include cloud sync, user accounts, or telemetry.
- Provider-specific optimization is forbidden by design; only provider-neutral transformations occur.
- External provider API calls are disabled by architecture; this runtime is local-only.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file promptguard_proxy-0.1.0.tar.gz.
File metadata
- Download URL: promptguard_proxy-0.1.0.tar.gz
- Upload date:
- Size: 29.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cadc7fd38be7bf65008b3bebb1236e409db092e44cd52710a276fd57774278f0
|
|
| MD5 |
dce71c29448ee701299a9820aecb135d
|
|
| BLAKE2b-256 |
6fb0e98df08fda6d1e1e234c3334a02d465491a9e82e7ea00cc82d38febee316
|
File details
Details for the file promptguard_proxy-0.1.0-py3-none-any.whl.
File metadata
- Download URL: promptguard_proxy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 42.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62e91d743a8b9ed274d27648a68457def7d2732c54b2f9c47ca055bfa4be78fc
|
|
| MD5 |
5c037bf056cf939afdde5281c9a516c4
|
|
| BLAKE2b-256 |
5f0e7e70445c411c2d679851fc92839e062b67bae9707462df42cd752fc7e7f1
|