Skip to main content

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.

Python 3.10+ License

🔒 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. See pricing for details.

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

  1. Sign up at https://gateforge.dev
  2. 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

  1. Local Processing: All PII detection happens locally in your environment
  2. Content Never Sent: Only metadata (tokens, cost) is sent to Gateforge API
  3. Automatic Masking: PII is replaced with tokens before sending to LLM providers
  4. 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

  1. Go to https://app.gateforge.dev/dashboard/pii/settings
  2. Select domain: Generic, Healthcare, Finance, Legal
  3. Choose backend: Presidio, Regex, Hybrid
  4. Set language: Auto-detect or specific language
  5. 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

  1. Verify your key at https://app.gateforge.dev/dashboard/keys
  2. Check it's not revoked
  3. Ensure you're using the correct environment

PII Not Detected

  1. Check your domain setting matches your use case
  2. Try different backends (presidio is most accurate)
  3. Add custom patterns for domain-specific entities

📚 Documentation

🤝 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


Made with ❤️ by the Gateforge team

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gateforge_sdk-0.1.0.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gateforge_sdk-0.1.0-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file gateforge_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: gateforge_sdk-0.1.0.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

Hashes for gateforge_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3bf26b0341807f2295127debac22d80632b74ebf6ea4ae4e07b1357816bd9040
MD5 0e39934ef5b4031b672eb02fb8eb07a5
BLAKE2b-256 01b6ed8650dab579fd28ee40be30af5f489729b27b513151b43b6ab2ee387d66

See more details on using hashes here.

File details

Details for the file gateforge_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gateforge_sdk-0.1.0-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

Hashes for gateforge_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 23a34a1a541b8d15363cda9b55d8f3c6a2c8e1ba9b0c869970029327b22ed720
MD5 b902572aad6da99c1ac8cf91b5a11bbd
BLAKE2b-256 3b5df0c3d18650db0d2613d3a88021c4bd97c059f77827e274250bbe8a565cc1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page