Add AI Governance to Your AI Agent in 5 Minutes
A hands-on tutorial: install the SDK, add PII redaction, enforce policies, and integrate with LangChain — all in under 5 minutes.
February 12, 2026 · 6 min read · Tork Network
Correction — 3 August 2026
Published February 2026. This tutorial installed the on-device package and then described cloud behaviour, which is a real conflation and not a wording nit. Code samples are corrected in place; the narrative claims are corrected here.
tork-governance is the on-device family. tork-governance makes the governance decision on your machine. PII detection, redaction and the returned verdict are computed on-device. With no API key it makes zero network calls: prompts, completions and detected PII values never leave the machine, and nothing appears in your dashboard.
Supply an API key and the SDK additionally reports a metadata-only attestation of each decision — the action taken, PII type labels and counts, a risk classification, policy labels and a salted fingerprint. It never sends input text, output text or PII values. The decision itself is still made on-device and is never delayed or changed by reporting. Those attestations appear in your dashboard and are included in the daily on-chain anchor — each one recorded as a client attestation (capture_mode=edge, attested_by=client), a claim Tork recorded but did not execute and cannot independently verify. Requires tork-governance 0.24.0+ (PyPI) or 0.11.0+ (npm).
A decision reported by an on-device SDK is recorded as a client attestation (capture_mode=edge, attested_by=client): a claim Tork recorded but did not execute and cannot independently verify. A decision made by @torknetwork/sdk is recorded as capture_mode=cloud, attested_by=tork — Tork made that call itself. Both are equally immutable once anchored; they differ in what is immutable. A client attestation freezes your claim. A server-governed receipt freezes Tork's own decision.
Two further corrections below: govern() is synchronous and returns output, not governed; and the ~20ms / sub-second latency figures describe the cloud path only. Local governance is free and unlimited — decisions made on your own machine are never metered. Evidence is what is metered: attestations, receipts and anchoring.
“Your AI agent just leaked a customer's Social Security number to a third-party API.”
That's not a hypothetical. It happened last month to a production agent with no governance layer. The fix took 30 seconds — adding one middleware call. The cleanup took three weeks.
This tutorial walks you through adding real governance to your AI agent. Not a toy demo — actual PII redaction, policy enforcement, and compliance receipts that hold up under audit. You'll be done before your coffee gets cold.
Prerequisites
- A Tork account (free tier — 5,000 calls/month, no credit card). Optional for this tutorial: the on-device package governs without an account.
- Your API key from the dashboard (starts with
tork_live_). Only needed for evidence — local governance needs no key. - Python 3.10+ or Node.js 18+
Step 1: Install the SDK
Pick your language. This is the on-device family — tork-governance decides on your machine and its entry class is Tork:
Want a dashboard row that records Tork's own decision rather than your attested claim? That is the cloud family: npm install @torknetwork/sdk, entry class TorkClient. The two are separate packages — tork-governance does not export TorkClient, so mixing them produces code that does not run.
Optionally set an API key. The on-device SDK governs fine without one, and with no key it makes no network calls at all:
Step 2: Add PII Redaction
The most common governance failure is PII leakage — user data passing through to LLMs, logs, or third-party APIs unredacted. Tork detects 50+ PII types across 13 regional formats and redacts them before they leave your system.
Python
JavaScript
The output field always contains the redacted version — there is no governed field, as this post originally stated. The original text is never logged or stored by Tork: on this package, detection and redaction happen in-memory on your machine and the text never leaves it.
Step 3: Enforce Policies
PII redaction keeps data safe. Policy enforcement keeps your agent safe. Define what your agent is — and isn't — allowed to do:
Python
JavaScript
On the on-device package the decision is driven by defaultAction, which is one of allow, redact, deny, or escalate — not the strict/standard/minimal names this post originally used. Named policy tiers and the tool-call rules below are cloud-path features, configured server-side:
Step 4: Govern Both Input and Output
Governing input catches prompt injection and PII in user messages. But LLMs can also hallucinate PII or leak training data in their responses. Govern both directions:
Python
JavaScript
Step 5: Integrate with LangChain
If you're using LangChain (or CrewAI, AutoGen, or any of the 128 supported frameworks), Tork plugs in as a callback or middleware — no refactoring required:
Python (LangChain)
JavaScript (LangChain.js)
The callback intercepts every LLM call, governs input and output, and produces a compliance receipt — zero changes to your existing chain logic. On the on-device package that receipt is a local object in the returned result; it is not sent anywhere and does not reach your dashboard by itself.
Step 6: Verify in the Dashboard
Correction, 3 Aug 2026: this step did not hold for the package installed in Step 1. Running the on-device SDK leaves your dashboard empty by design — with no API key it makes no network calls. Getting these rows requires an API key and an SDK version carrying attestation reporting — tork-governance 0.24.0+ on PyPI or 0.11.0+ on npm, both published 3 Aug 2026. A row reported that way is stored as a client attestation (a claim Tork recorded, not a decision Tork made or verified). The list below describes the cloud path, @torknetwork/sdk, where the decision and therefore the receipt are Tork's own.
Run your agent against the cloud path and head to the Tork dashboard. You'll see:
- API call history — every govern call with timestamps, latency, and action taken
- PII detections — types found, redaction counts, and trends over time
- Policy violations — blocked and flagged requests with full context
- Compliance receipts — HMAC hash-chained audit trail for every decision, included in the daily on-chain anchor
- TORKING-X score — your 0–100 governance maturity rating across nine dimensions
Compliance receipts are the part auditors care about. Each receipt is cryptographically chained to the previous one, so tampering with any single entry invalidates the entire chain. Hand these to your compliance team for HIPAA, GDPR, SOC 2, or PCI-DSS reporting.
What You Just Built
In under 5 minutes, you added:
- PII redaction for 50+ data types across 13 regional formats
- Policy enforcement with block, flag, and allow actions
- Bidirectional governance on both user input and LLM output
- Framework integration via LangChain callbacks (or any of 128 adapters)
- Immutable compliance receipts for audit and regulatory reporting — local objects on the on-device package; reaching the dashboard needs an API key and tork-governance 0.24.0+ (PyPI) or 0.11.0+ (npm), and lands as a client attestation
On the cloud path that costs ~20ms added overhead at the edge, with cloud governance typically completing in under a second. Those figures are the cloud path's; the on-device package makes no network call, so its cost is local compute only. Your agent is now governed and auditable — without a single architectural change.
Next Steps
- Read the full documentation for advanced policy configuration, custom rules, and the complete API reference
- Explore MCP Security if your agent uses the Model Context Protocol
- Try Human-in-the-Loop for high-stakes actions like payments and database writes
- Check out Tork Guardian for OpenClaw if you're building with OpenClaw skills
- See pricing plans for higher limits, custom policies, SSO, and dedicated support
Ready to govern your agent?
Free tier includes 5,000 API calls per month. No credit card required.
Get Your API KeyTork Network Pty Ltd — Sydney, Australia