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.
Release files for promptguard-proxy 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| promptguard_proxy-0.1.0.tar.gz | 29.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| promptguard_proxy-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 71.9 kB
Release files / promptguard_proxy-0.1.0.tar.gz
| Download URL | promptguard_proxy-0.1.0.tar.gz |
|---|---|
| Size | 29.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cadc7fd38be7bf65008b3bebb1236e409db092e44cd52710a276fd57774278f0
|
|
BLAKE2b-256 checksum How to use checksums |
6fb0e98df08fda6d1e1e234c3334a02d465491a9e82e7ea00cc82d38febee316
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / promptguard_proxy-0.1.0-py3-none-any.whl
| Download URL | promptguard_proxy-0.1.0-py3-none-any.whl |
|---|---|
| Size | 42.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
62e91d743a8b9ed274d27648a68457def7d2732c54b2f9c47ca055bfa4be78fc
|
|
BLAKE2b-256 checksum How to use checksums |
5f0e7e70445c411c2d679851fc92839e062b67bae9707462df42cd752fc7e7f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|