Privacy-first LLMOps SDK — Automatic PII masking, cost tracking, and prompt management for LLM applications
Project description
Gateforge SDK
Privacy-first LLMOps SDK — Automatic PII masking, cost tracking, and prompt management for LLM applications.
🔒 What is Gateforge?
Gateforge is an LLMOps platform that automatically protects sensitive data (PII) in your LLM applications. The SDK processes everything locally — no content ever leaves your infrastructure.
Note: This SDK is free and open source (MIT license). It requires a Gateforge account to use. We offer a generous free tier: 1,000 requests/month.
Key Features:
- ✅ Automatic PII Detection & Masking — Names, emails, SSN, phone numbers, credit cards, and more
- ✅ Multi-Provider Support — OpenAI, Anthropic, Gemini with unified interface
- ✅ Cost Tracking — Real-time metrics and dashboards
- ✅ Domain-Specific Detection — Healthcare, Finance, Legal, Generic
- ✅ Custom Regex Patterns — Add your own entity types
- ✅ Zero Network Overhead — All PII processing happens locally
🚀 Quick Start
Installation
pip install gateforge-sdk
With provider support:
pip install gateforge-sdk[openai] # OpenAI only
pip install gateforge-sdk[anthropic] # Anthropic only
pip install gateforge-sdk[gemini] # Google Gemini only
pip install gateforge-sdk[all] # All providers
Get Your API Key
- Sign up at https://gateforge.dev
- Get your API key from https://app.gateforge.dev/dashboard/keys
Basic Usage
import gateforge
# Initialize once at startup
gateforge.init(
api_key="your-gateforge-api-key",
openai_key="your-openai-key",
)
# Make LLM calls with automatic PII protection
response = gateforge.chat(
model="gpt-4.1-nano",
messages=[
{"role": "user", "content": "My email is john@example.com, can you help?"}
]
)
print(response.content) # "Hello! I'd be happy to help..."
print(response.pii_detected) # ['EMAIL']
print(response.tokens) # 45
print(response.cost_usd) # 0.000023
📖 Examples
Healthcare Domain
response = gateforge.chat(
model="gpt-4.1-nano",
messages=[
{
"role": "user",
"content": "Patient John Doe, SSN 123-45-6789, has hypertension. Recommend treatment."
}
],
pii_domain="healthcare" # Detects medical entities
)
print(response.pii_detected) # ['PERSON', 'SSN', 'SYMPTOM']
Multiple Providers
import gateforge
gateforge.init(
api_key="your-gateforge-key",
openai_key="sk-...",
anthropic_key="sk-ant-...",
gemini_key="...",
)
# OpenAI
r1 = gateforge.chat(model="gpt-4.1-nano", messages=[...])
# Anthropic
r2 = gateforge.chat(model="claude-haiku-4-5", messages=[...])
# Gemini
r3 = gateforge.chat(model="gemini-2.5-flash", messages=[...])
Custom PII Patterns
Configure custom patterns in your dashboard at https://app.gateforge.dev/dashboard/pii/settings, and the SDK will download them automatically.
🔧 Configuration
Initialization Options
gateforge.init(
api_key="your-gateforge-api-key", # Required
openai_key="sk-...", # Optional
anthropic_key="sk-ant-...", # Optional
gemini_key="...", # Optional
)
Chat Parameters
response = gateforge.chat(
model="gpt-4.1-nano", # Required: model name
messages=[...], # Required: chat messages
pii_domain="generic", # Optional: "generic", "healthcare", "finance", "legal"
provider_key="sk-...", # Optional: override provider key
prompt_id="user-signup", # Optional: for prompt tracking
temperature=0.7, # Optional: model parameters
max_tokens=500, # Optional: model parameters
)
Response Object
response = gateforge.chat(...)
response.content # str: The response content
response.pii_detected # list[str]: Detected PII types
response.tokens # int: Total tokens
response.prompt_tokens # int: Input tokens
response.completion_tokens # int: Output tokens
response.cost_usd # float: Cost in USD
response.latency_ms # float: Latency in milliseconds
response.model # str: Model used
response.raw # dict: Raw provider response
🔒 Privacy & Security
How it Works
- Local Processing: All PII detection happens locally in your environment
- Content Never Sent: Only metadata (tokens, cost) is sent to Gateforge API
- Automatic Masking: PII is replaced with tokens before sending to LLM providers
- Automatic Rehydration: Responses are reconstructed with original context
What Gets Detected?
- Personal: Names, emails, phone numbers, addresses
- Financial: Credit cards, bank accounts, SSN, tax IDs
- Healthcare: Medical record numbers, symptoms, diagnoses
- Technical: IP addresses, URLs, API keys
- Custom: Your own regex patterns
Supported Backends
- Presidio (default): ML-based, highest accuracy
- Regex: Pattern matching, fastest
- Hybrid: Combined ML + regex
- GLiNER: Zero-shot NER
- Transformers: HuggingFace models
📊 Dashboard & Monitoring
View real-time metrics at https://app.gateforge.dev/dashboard:
- 📈 Request volume and trends
- 💰 Cost breakdown by model and provider
- ⚡ Latency analytics
- 🔒 PII detection statistics
- 🔑 API key management
🛠️ Advanced Usage
Streaming (Coming Soon)
for chunk in gateforge.chat_stream(model="gpt-4.1-nano", messages=[...]):
print(chunk.content, end="", flush=True)
Async Support (Coming Soon)
response = await gateforge.achat(model="gpt-4.1-nano", messages=[...])
Direct Anonymization
from gateforge.pii import anonymize_messages
context = {
"tenant_id": "user-123",
"case_id": "case-456",
"thread_id": "thread-789",
"actor_id": "user"
}
anonymized, entities = anonymize_messages(
messages=[{"role": "user", "content": "My email is john@example.com"}],
domain="generic",
backend="presidio",
context=context
)
print(anonymized) # [{"role": "user", "content": "My email is [EMAIL_001]"}]
print(entities) # ['EMAIL']
🌐 Supported Models
OpenAI
- GPT-4.1-nano, GPT-4.1-mini, GPT-4.1, GPT-4.1-turbo
- GPT-4o, GPT-4o-mini
- GPT-3.5-turbo
Anthropic
- Claude Haiku 4-5
- Claude Sonnet 4-5
- Claude Opus 4
Google Gemini
- Gemini 2.5 Flash
- Gemini 2.5 Pro
📝 Configuration via Dashboard
PII Settings
- Go to https://app.gateforge.dev/dashboard/pii/settings
- Select domain: Generic, Healthcare, Finance, Legal
- Choose backend: Presidio, Regex, Hybrid
- Set language: Auto-detect or specific language
- Add custom regex patterns
The SDK downloads your configuration automatically on init.
Custom Patterns
Add patterns like:
Entity Type: EMPLOYEE_ID
Regex: EMP-\d{6}
Confidence: 0.95
🐛 Troubleshooting
ImportError: No module named 'gateforge'
pip install gateforge-sdk
RuntimeError: Call gateforge.init() first
Make sure to initialize before making calls:
gateforge.init(api_key="your-key")
API Key Not Working
- Verify your key at https://app.gateforge.dev/dashboard/keys
- Check it's not revoked
- Ensure you're using the correct environment
PII Not Detected
- Check your domain setting matches your use case
- Try different backends (presidio is most accurate)
- Add custom patterns for domain-specific entities
📚 Documentation
- Website: https://gateforge.dev
- Dashboard: https://app.gateforge.dev
- API Docs: https://api.gateforge.dev/docs
🤝 Contributing
Contributions are welcome! Please open an issue or submit a pull request.
📄 License
MIT License - See LICENSE for details.
Important: While the SDK is open source, the Gateforge service is commercial. You need a Gateforge account (free tier available) to use this SDK.
🔗 Links
💬 Support
- Email: support@gateforge.dev
- Issues: GitHub Issues
Made with ❤️ by the Gateforge team
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 gateforge_sdk-0.1.1.tar.gz.
File metadata
- Download URL: gateforge_sdk-0.1.1.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1494b5e19477ecd9572323062978ec9f685cf4ee66ca6485ede21534f4a206a0
|
|
| MD5 |
1d5dceb69fa426541dc1c8081c737fbb
|
|
| BLAKE2b-256 |
746e429c779ff696ddfc5c4f24cdb05a37e57b9cbb59b60df8e225ccdad4ff63
|
File details
Details for the file gateforge_sdk-0.1.1-py3-none-any.whl.
File metadata
- Download URL: gateforge_sdk-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58774a6901fdd97ed84f34ffbbacd62cac76829edfef8a82389a032cc74d936f
|
|
| MD5 |
e3e38ea0b73465c92b0beed7cfbab475
|
|
| BLAKE2b-256 |
bc3bb1a815071ae0d0cd381b4d85c88be2968b140c6a7d461daf61c73991d24f
|