High-performance LLM token optimization engine
Project description
Sieve
Sieve is a language-agnostic, infrastructure-first library for LLM Token Optimization and Middleware. It is the "gorilla/mux" of the AI era — a tool developers can drop into their stack to automatically "sift" prompts, reducing token costs and preventing prompt injection in-flight.
Why Sieve?
- Cost Reduction: LLM APIs charge by the token. Conversational filler ("Hey, could you please...", "I was just wondering if...") wastes money and dilutes semantic intent. Sieve strips this noise before it ever hits the network.
- Performance: Less tokens = faster inference (TTFT).
- Portability: Available as a high-performance native library for Rust and Python, and as a pure-Go library/middleware for easy deployment.
- Security (Coming Soon): In-flight prompt injection detection and PII scrubbing.
Architecture
At its heart is Sieve-Core, a regex-based noise reducer written in Rust for maximum throughput. It is exposed to Python via PyO3, and to Go via a pure-Go reimplementation (for ease of use) with identical behavior.
Depending on your stack, you can use Sieve as a library or as an ultra-fast local HTTP proxy ("Sidecar mode").
+-----------------------------------------------------+
| Your App |
| +-------------+ +-------------+ +-------------+ |
| | Python | | Go API | | Any Backend | |
| | (PyO3 Lib) | | (Middleware)| | (Sidecar) | |
| +------+------+ +------+------+ +------+------+ |
+---------|----------------|----------------|---------+
| | |
<Sifted> <Sifted> <Sifted>
| | |
v v v
+-----------------------------------------------------+
| LLM API |
| (OpenAI, Anthropic, etc.) |
+-----------------------------------------------------+
Quick Start
Python (Native Binding)
pip install sieve-core
from sieve import sift, SiftLevel
prompt = "Hello there, I was wondering if you could please summarize this document for me?"
result = sift(prompt, level=SiftLevel.High)
print(result.sifted)
# "Summarize this document"
print(f"Compressed by {result.compression_ratio:.2f}x")
Go (Library & Middleware)
go get github.com/sieve-ai/sieve-go
Basic Library Usage
import "github.com/sieve-ai/sieve-go"
result := sieve.Sift("Could you please help me write a function?", sieve.Medium)
fmt.Println(result.Sifted) // "help write a function?"
HTTP Middleware Example
Sieve makes it trivial to transparently sift requests passing through your API before they hit your LLM handlers.
package main
import (
"io"
"net/http"
"fmt"
"github.com/sieve-ai/sieve-go"
)
func main() {
// 1. Create your LLM handler (expects JSON with a "prompt" field)
llmHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
body, _ := io.ReadAll(r.Body)
// body here is already sifted by the middleware!
fmt.Fprintf(w, "Received prompt: %s", string(body))
})
// 2. Wrap it with Sieve Middleware
// We tell Sieve to look for the "prompt" key in the JSON body
// and apply High compression.
sieveMiddleware := sieve.NewMiddleware(
sieve.WithLevel(sieve.High),
sieve.WithTargetKey("prompt"),
)
http.Handle("/generate", sieveMiddleware.Wrap(llmHandler))
fmt.Println("Server listening on :8080...")
http.ListenAndServe(":8080", nil)
}
Any Language ("Sidecar Proxy" Mode)
For languages without native bindings, run Sieve as a local background process.
# Start the Go proxy on port 4141
go run github.com/sieve-ai/sieve-go/cmd/sieve-proxy -port 4141
Then query it from anywhere:
curl -X POST http://localhost:4141/sift \
-H "Content-Type: application/json" \
-d '{"prompt": "Could you please help me write a function?", "level": "high"}'
# Response:
# {"original":"Could you please help me write a function?","sifted":"help write a function?","tokens_removed":5,"compression_ratio":0.44}
Sift Levels
Low: Removes highly obvious conversational fillers ("please", "could you kindly").Medium: Removes fillers + hedge words ("maybe", "I think", "sort of").High: Aggressive token scrubbing — strips almost everything non-essential ("help me", "if possible").
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 Distributions
Built Distributions
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 sieve_core-0.1.0-cp314-cp314-macosx_11_0_arm64.whl.
File metadata
- Download URL: sieve_core-0.1.0-cp314-cp314-macosx_11_0_arm64.whl
- Upload date:
- Size: 825.8 kB
- Tags: CPython 3.14, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b98f042ac213a1cc0e22e274b22a0d48d78bd8ba5939b328b1821c87e5ce948
|
|
| MD5 |
c9f03c7c49ee4523934d48fef9081690
|
|
| BLAKE2b-256 |
d0d8a3b78d56e7fdc1976559c1a1ff765afc5346c645520ec4c533c73cd248cb
|
File details
Details for the file sieve_core-0.1.0-cp314-cp314-macosx_10_12_x86_64.whl.
File metadata
- Download URL: sieve_core-0.1.0-cp314-cp314-macosx_10_12_x86_64.whl
- Upload date:
- Size: 869.3 kB
- Tags: CPython 3.14, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
142b1bfae144fd45556a53ba82b298af3fa34e6057ea802aaf881510ba1e2ed5
|
|
| MD5 |
25c5dc6eb01e44ce9e0321e794210e2d
|
|
| BLAKE2b-256 |
4c2291faed28203335539509991af2118a581789ef2163cc97a397a9de60e3a4
|
File details
Details for the file sieve_core-0.1.0-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: sieve_core-0.1.0-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 731.0 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c69f1c537b6401455b753c95f6697261deb0a6b37abd0bbdd8a532d77beb83b
|
|
| MD5 |
bb80ae065725a24fd3eaeb326f1ebacc
|
|
| BLAKE2b-256 |
e6a4e5ab67983ec538377f9ec42c07501e425a1122db2d318dca9137d4c43a4b
|
File details
Details for the file sieve_core-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: sieve_core-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 981.7 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1212ee8c1e5d91eab0426a2742042e3cf7153f404809fe676c760f31a024d626
|
|
| MD5 |
8fe951126e0f1612a58a8378834e0b7c
|
|
| BLAKE2b-256 |
ee85679dde17f408164536a6d3946df08026bfd7e53b85f83e80269f6706ed4d
|