On-device AI governance with PII detection and cryptographic receipts
Project description
Tork Governance Python SDK
On-device AI governance with PII detection, redaction, and cryptographic receipts.
Installation
pip install tork-governance
With optional framework support:
pip install tork-governance[langchain]
pip install tork-governance[fastapi]
pip install tork-governance[all]
Quick Start
from tork_governance import Tork
tork = Tork()
# Detect and redact PII
result = tork.govern("My SSN is 123-45-6789 and email is john@example.com")
print(result.output) # "My SSN is [SSN_REDACTED] and email is [EMAIL_REDACTED]"
print(result.pii.types) # ['ssn', 'email']
print(result.receipt.receipt_id) # Cryptographic receipt ID
Supported AI Frameworks (67 Adapters)
LLM Provider SDKs
- OpenAI SDK - Direct OpenAI API governance with streaming
- Anthropic SDK - Claude API governance
- Google Gemini - Gemini API with multi-modal support
- AWS Bedrock - Bedrock with Claude, Titan, Llama support
- Azure OpenAI - Azure OpenAI Service governance
- Cohere SDK - Chat, embed, rerank, classify governance
- Mistral SDK - Mistral AI chat and embeddings governance
- Groq SDK - Groq LPU chat and audio transcription governance
- Together AI SDK - Together AI chat, completions, and embeddings governance
- Replicate SDK - Replicate model run and predictions governance
- LocalAI - Local OpenAI-compatible LLM governance
- LM Studio - LM Studio local inference governance
- GPT4All - GPT4All local LLM governance
- PrivateGPT - PrivateGPT private document AI governance
LLM Orchestration
- LangChain - Chain and agent governance
- LlamaIndex - Query engine and retriever governance
- Semantic Kernel - Microsoft SK filters and plugins
- Haystack - Pipeline and document processor governance
- LiteLLM - Unified interface for 100+ LLMs
- vLLM - High-throughput LLM serving
- Ollama - Local LLM governance
Agent Frameworks
- CrewAI - Multi-agent crew governance
- AutoGen - Microsoft AutoGen agent governance
- OpenAI Agents SDK - Function calling governance
- SuperAGI - Autonomous agent governance
- MetaGPT - Multi-agent role governance
- BabyAGI - Task-driven agent governance
- AgentGPT - Goal-oriented agent governance
Structured Output & Guardrails
- Pydantic AI - Type-safe AI with governance
- Instructor - Structured outputs governance
- DSPy - Stanford DSPy module governance
- Guidance - Microsoft Guidance governance
- LMQL - Query language governance
- Outlines - Structured generation governance
- Marvin - AI function governance
- Guardrails AI - Validator integration
- NeMo Guardrails - NVIDIA Colang integration
- Rebuff - Prompt injection detection with governance
- LLM Guard - Input/output scanning with governance
AI Development Frameworks
- Mirascope - Decorator-based LLM call governance
- Magentic - @prompt decorator governance
- txtai - Embeddings and pipeline governance
- ChatDev - Multi-agent software development governance
- CAMEL - Multi-agent role-playing governance
Visual Builders & Platforms
- Flowise - Visual workflow governance
- Langflow - Visual LangChain governance
- Dify - Low-code AI platform governance
Vector Databases
- ChromaDB - AI-native vector DB governance
- Pinecone - Managed vector DB governance
- Weaviate - Vector search governance
- Qdrant - Vector similarity governance
- Milvus - Scalable vector DB governance
LLM Observability
- LangSmith - LangChain tracing governance
- Langfuse - LLM analytics governance
- Phoenix - Arize Phoenix observability
- Helicone - LLM monitoring governance
- Weights & Biases - Experiment tracking governance
- Arize - ML observability governance
- Portkey - AI gateway governance
- PromptLayer - Prompt management governance
- Humanloop - Prompt optimization governance
Protocols
- MCP - Model Context Protocol governance
Web Frameworks
- FastAPI - Middleware and dependency injection
- Django - Middleware integration
- Flask - Extension and decorator support
- Starlette - ASGI middleware
- Tornado - RequestHandler mixin and middleware
- Pyramid - Tween and middleware governance
- Sanic - Async request/response middleware
Framework Examples
LiteLLM - Unified LLM Interface
from tork_governance.adapters.litellm import TorkLiteLLMProxy, govern_completion
# Option 1: Governed proxy client
proxy = TorkLiteLLMProxy()
response = proxy.completion(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "My SSN is 123-45-6789"}]
)
# Option 2: One-off governed completion
response = govern_completion(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "My email is john@example.com"}]
)
Ollama - Local LLM Governance
from tork_governance.adapters.ollama import TorkOllamaClient, govern_generate
# Governed Ollama client
client = TorkOllamaClient()
response = client.generate(
model="llama2",
prompt="My phone number is 555-123-4567"
)
print(response["response"]) # PII redacted
# Chat with governance
response = client.chat(
model="llama2",
messages=[{"role": "user", "content": "My SSN is 123-45-6789"}]
)
ChromaDB - Vector Database Governance
from tork_governance.adapters.chromadb import TorkChromaClient
# Governed ChromaDB client
client = TorkChromaClient()
collection = client.get_or_create_collection("my_docs")
# Documents are governed before storage
collection.add(
documents=["User John has SSN 123-45-6789"],
ids=["doc1"]
)
# Query results are governed before returning
results = collection.query(query_texts=["Find user data"])
LangChain Integration
from langchain.llms import OpenAI
from tork_governance.adapters.langchain import TorkCallbackHandler
llm = OpenAI(callbacks=[TorkCallbackHandler()])
response = llm("My credit card is 4111-1111-1111-1111")
# PII automatically redacted in prompts and responses
FastAPI Middleware
from fastapi import FastAPI
from tork_governance.adapters.fastapi import TorkFastAPIMiddleware
app = FastAPI()
app.add_middleware(TorkFastAPIMiddleware)
@app.post("/chat")
async def chat(message: str):
# Request body is automatically governed
return {"response": message}
PII Detection
Detects 50+ PII types across multiple regions:
| Category | Types |
|---|---|
| US | SSN, EIN, ITIN, Passport, Driver's License, Phone |
| Australia | TFN, ABN, ACN, Medicare, Driver's License |
| EU/UK | NINO, NHS, IBAN, VAT, National ID |
| Financial | Credit Card, Bank Account, SWIFT/BIC |
| Healthcare | MRN, NPI, DEA, ICD-10 codes |
| Universal | Email, IP Address, URL, DOB, Phone |
Compliance Support
- GDPR - EU data protection
- HIPAA - Healthcare (18 PHI identifiers)
- PCI-DSS - Payment card data
- SOC 2 - Security controls
- CCPA/CPRA - California privacy
- FERPA - Education records
- GLBA - Financial privacy
- COPPA - Children's privacy
Cryptographic Receipts
Every governance action generates a verifiable receipt:
result = tork.govern("Sensitive data here")
receipt = result.receipt
print(receipt.receipt_id) # Unique identifier
print(receipt.timestamp) # ISO 8601 timestamp
print(receipt.input_hash) # SHA-256 of input
print(receipt.output_hash) # SHA-256 of output
print(receipt.policy_version) # Applied policy version
Configuration
from tork_governance import Tork, TorkConfig
tork = Tork(
config=TorkConfig(
policy_version="1.0.0",
default_action="redact", # or "allow", "deny"
custom_patterns={
"employee_id": r"EMP-\d{6}"
}
)
)
Documentation
License
MIT License - see LICENSE for details.
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 tork_governance-0.20.0.tar.gz.
File metadata
- Download URL: tork_governance-0.20.0.tar.gz
- Upload date:
- Size: 219.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f45ec69bc98e44a7f86970b4d29925671dd8583ed6318eaa02bfeca891a5e1b
|
|
| MD5 |
658e740cb98beb9278aa8ca6146ff6e0
|
|
| BLAKE2b-256 |
3d512db3f8d71024a942090beac3c6fbbd8ca2581e48f1cbc6099ceec7623ee0
|
File details
Details for the file tork_governance-0.20.0-py3-none-any.whl.
File metadata
- Download URL: tork_governance-0.20.0-py3-none-any.whl
- Upload date:
- Size: 184.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65c708a1f09cfa0a0510b80682a4a69598a2243d896a5de821c8cb020dd8efb4
|
|
| MD5 |
e2ba2340be30404c2d2be84ba6b1c1ab
|
|
| BLAKE2b-256 |
8469d07dd54f393e47252ff58fb7e7e6e7661b2ff12910b723bb14720b78c9e8
|