On-device AI governance with PII detection, redaction, and cryptographic receipts for Ruby applications.
Add to your Gemfile:
gem 'tork-governance'Or install directly:
gem install tork-governancerequire 'tork_governance'
tork = TorkGovernance::Client.new
# Detect and redact PII
result = tork.govern("My SSN is 123-45-6789 and email is john@example.com")
puts result.output # "My SSN is [SSN_REDACTED] and email is [EMAIL_REDACTED]"
puts result.pii.types # ['ssn', 'email']
puts result.receipt.id # Cryptographic receipt IDActivate country-specific and industry-specific PII patterns:
tork = TorkGovernance::Client.new
# 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- Rails - Middleware and controller integration
- Grape - API middleware and helpers
# config/application.rb
module MyApp
class Application < Rails::Application
config.middleware.use TorkGovernance::Middleware::Rails,
protected_paths: ['/api/'],
skip_paths: ['/api/health']
end
end# In controllers
class ChatController < ApplicationController
def create
tork_result = request.env['tork.result']
render json: { status: 'ok', receipt_id: tork_result&.receipt&.id }
end
endrequire 'tork_governance/middleware/grape'
class API < Grape::API
use TorkGovernance::Middleware::Grape,
protected_paths: ['/api/'],
skip_paths: ['/api/health']
helpers TorkGovernance::Middleware::GrapeHelpers
post '/chat' do
result = tork_result
receipt_id = tork_receipt_id
if tork_blocked?
error!({ error: 'Content blocked' }, 403)
end
{ status: 'ok', receipt_id: receipt_id }
end
endhelpers TorkGovernance::Middleware::GrapeHelpers
# Available helpers:
tork_result # Get full governance result
tork_receipt_id # Get receipt ID
tork_redacted_content # Get redacted content
tork_blocked? # Check if request was blocked
tork_redacted? # Check if content was redacted
require_tork_governance! # Raises 403 if blockedTorkGovernance.configure(
api_key: ENV['TORK_API_KEY'],
policy_version: '1.0.0',
default_action: :redact
)Detects 50+ PII types including:
| Category | Types |
|---|---|
| US | SSN, EIN, ITIN, Passport, Driver's License |
| Australia | TFN, ABN, ACN, Medicare |
| Financial | Credit Card, Bank Account, SWIFT/BIC |
| Universal | Email, IP Address, URL, Phone, DOB |
MIT License - see LICENSE for details.