Skip to main content

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.

PyPI version Python 3.9+ License: MIT

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

Regional PII Detection (v1.1)

Activate country-specific and industry-specific PII patterns with the optional region and industry parameters:

from tork_governance import Tork

tork = Tork()

# UAE regional detection — Emirates ID, +971 phone, PO Box
result = tork.govern(
    "Emirates ID: 784-1234-1234567-1",
    region=["ae"]
)

# Multi-region + industry
result = tork.govern(
    "Aadhaar: 1234 5678 9012, ICD-10: J45.20",
    region=["in"],
    industry="healthcare"
)

# Available regions: AU, US, GB, EU, AE, SA, NG, IN, JP, CN, KR, BR
# Available industries: healthcare, finance, legal

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


Download files

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

Source Distribution

tork_governance-0.22.0.tar.gz (243.5 kB view details)

Uploaded Source

Built Distribution

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

tork_governance-0.22.0-py3-none-any.whl (220.9 kB view details)

Uploaded Python 3

File details

Details for the file tork_governance-0.22.0.tar.gz.

File metadata

  • Download URL: tork_governance-0.22.0.tar.gz
  • Upload date:
  • Size: 243.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.1

File hashes

Hashes for tork_governance-0.22.0.tar.gz
Algorithm Hash digest
SHA256 0165676e64f8e271deebf7cdb5bcacc2354f27716ffa2fe6b13e0adb8791e884
MD5 29087d29342f4345664e4c7396e3f898
BLAKE2b-256 bd94f3d6cbd1f27032859151d6dfd05ada5c3b1cdc2323b826cc8e4f48a46f77

See more details on using hashes here.

File details

Details for the file tork_governance-0.22.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tork_governance-0.22.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5d2cf7c1da5a7d06a9053a197bb1a3afd198eaaa21536cf89e9dc7dd7124cfda
MD5 3606d0e358ed0235d6f415dc2dffe328
BLAKE2b-256 7444c0a4cda995e7e83ebe32ffdbd58e064d4f9833643d58ccf7cf2faf5af86d

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