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

Supported AI Frameworks (57 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

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

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

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.19.0.tar.gz (203.4 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.19.0-py3-none-any.whl (166.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tork_governance-0.19.0.tar.gz
  • Upload date:
  • Size: 203.4 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.19.0.tar.gz
Algorithm Hash digest
SHA256 cc28f056efc7b8a838e9f73d357d865fa4b8f4010d4d794c229735424074ae26
MD5 7ba1a7d9649c8425d44dccf2389b48e6
BLAKE2b-256 960412688bc40a0b37d21108f1be012355da51069f46e486a8ef34df43f73dd1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tork_governance-0.19.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a98bdcc2cacfae486b302601242e90408fbe650c7c3c7dca4ffe7f66a8e1138a
MD5 439a493202053e8bab30979e351ded16
BLAKE2b-256 1d90a4b58c8b37056c7ee28c858d1cd22df526a628ff5e4770edaa50dc13174a

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