Core Features

RAG Enforcement

Ensure AI responses are grounded in your source documents and prevent hallucinations.

Overview

RAG Enforcement governs the chunks your retriever returns before they reach the model: it checks each chunk came from an approved source, scans it for PII, and applies your content policy.

Source Allowlisting

Reject chunks from unapproved sources

PII Screening

Detect and redact PII in retrieved text

Content Policy

Block chunks that violate your policy

Validating Retrieved Chunks

RAG enforcement runs server-side, in the Tork cloud. You send the chunks your retriever returned and Tork checks each one against your configured source allowlist, PII rules and content policy before they reach the model.

The cloud client class TorkClient ships in @torknetwork/sdk (npm) — a different package from the on-device tork-governance family, whose only entry class is Tork. There is no Python cloud client, so from Python call the REST endpoint directly with a Bearer token.

python
import os
import requests

# The chunks your retriever returned
chunks = [
    {
        "chunkId": "about-1",
        "content": "Tork was founded in 2024 and is headquartered in Sydney.",
        "sourceUri": "https://docs.tork.network/about",
    },
    {
        "chunkId": "install-1",
        "content": "Tork supports Python 3.10+ and Node.js 18+.",
        "sourceUri": "https://docs.tork.network/installation",
    },
]

resp = requests.post(
    "https://tork.network/api/v1/rag",
    headers={
        "Authorization": f"Bearer {os.environ['TORK_API_KEY']}",
        "Content-Type": "application/json",
    },
    json={"action": "validate", "chunks": chunks},
    timeout=10,
)
resp.raise_for_status()
data = resp.json()

print(f"Passed: {data['validation']['passed']}")
print(f"Action: {data['validation']['overallAction']}")
print(f"Blocked: {data['summary']['chunksBlocked']}")

for r in data["results"]:
    print(f"  - {r['chunkId']}: {r['action']} (source ok: {r['sourceCheckPassed']})")
javascript
// npm install @torknetwork/sdk
import { TorkClient } from '@torknetwork/sdk';

const client = new TorkClient({ apiKey: process.env.TORK_API_KEY });

// Tork makes the decision server-side, so the result is recorded as
// capture_mode=cloud, attested_by=tork.
const result = await client.govern(retrievedChunk.content);
console.log(result.action);

Chunk-Level Analysis

Every chunk comes back with the outcome of each check that ran against it:

json
{
  "validation": {
    "requestId": "rag_01J...",
    "passed": true,
    "overallAction": "allow",
    "processingTimeMs": 42
  },
  "summary": {
    "totalChunks": 2,
    "chunksAllowed": 2,
    "chunksBlocked": 0,
    "chunksRedacted": 0
  },
  "findings": {
    "uniqueSources": 2,
    "piiTypesFound": [],
    "policyViolationsFound": []
  },
  "results": [
    {
      "chunkId": "about-1",
      "passed": true,
      "action": "allow",
      "sourceCheckPassed": true,
      "piiCheckPassed": true,
      "contentPolicyPassed": true,
      "sizeCheckPassed": true
    },
    {
      "chunkId": "install-1",
      "passed": true,
      "action": "allow",
      "sourceCheckPassed": true,
      "piiCheckPassed": true,
      "contentPolicyPassed": true,
      "sizeCheckPassed": true
    }
  ]
}

Source Rules and Config

Which sources are allowed is configured as source rules. Rules are matched by priority; the first match wins, and defaultAction decides what happens to a chunk no rule matched.

python
import os
import requests

HEADERS = {
    "Authorization": f"Bearer {os.environ['TORK_API_KEY']}",
    "Content-Type": "application/json",
}

# Allow an internal documentation domain
requests.post(
    "https://tork.network/api/v1/rag",
    headers=HEADERS,
    json={
        "action": "create_source",
        "sourceName": "internal-docs",
        "sourceType": "domain",
        "sourcePattern": "docs.internal.example.com",
        "accessMode": "allow",
        "priority": 100,
        "requirePiiCheck": True,
        "requireContentPolicy": True,
        "maxChunkSize": 10000,
    },
    timeout=10,
).raise_for_status()

Per-request behaviour is set with the optional config object on a validate call:

json
{
  "action": "validate",
  "chunks": [ /* ... */ ],
  "config": {
    "defaultAction": "block",
    "enablePiiCheck": true,
    "enableContentPolicy": true,
    "redactPii": true,
    "maxChunkSize": 10000,
    "allowPartialBatch": true
  }
}

Best Practice: Validate retrieved chunks before they enter the prompt, not after the model has answered — once unapproved text is in the context window, the response is already derived from it.

Documentation

Learn to integrate TORK

Upgrade Plan

Current: free

Support

Get help from our team