Skip to main content

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 PromptRequest model.
  • 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

  1. Incoming HTTP payload reaches a provider endpoint.
  2. Adapter parses provider payload into PromptRequest.
  3. Optimization pipeline executes pass chain.
  4. Prompt AST is generated for diagnostics and pruning support.
  5. Optimized request is serialized by adapter.
  6. Local response with compressed prompt and stats is returned.
  7. 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, statistics
  • promptguard_proxy/api: FastAPI app, routes, dependencies
  • promptguard_proxy/storage: runtime storage utilities
  • promptguard_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 /health
  • GET /stats
  • GET /metrics
  • GET /providers
  • GET /history/context
  • WS /dashboard/ws
  • POST /v1/chat/completions
  • POST /v1/messages
  • POST /history/memory
  • POST /reload

CLI Commands

  • promptguard init
  • promptguard start
  • promptguard stop
  • promptguard status
  • promptguard config
  • promptguard 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)

Source distribution for promptguard-proxy 0.1.0
File Size Uploaded
promptguard_proxy-0.1.0.tar.gz 29.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for promptguard-proxy 0.1.0
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page