Core Features

RAG Enforcement

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

Overview

RAG Enforcement validates that AI-generated responses are properly grounded in retrieved documents, preventing hallucinations and ensuring factual accuracy.

Source Validation

Verify claims against source documents

Citation Tracking

Ensure proper attribution

Hallucination Detection

Flag unsupported statements

Validating RAG Responses

Check if an AI response is properly grounded in source documents:

python
from tork_governance import TorkClient

client = TorkClient()

# Your retrieved documents
sources = [
    {
        "content": "Tork was founded in 2024 and is headquartered in Sydney.",
        "url": "https://docs.tork.network/about",
        "title": "About Tork"
    },
    {
        "content": "Tork supports Python 3.8+ and Node.js 18+.",
        "url": "https://docs.tork.network/installation",
        "title": "Installation Guide"
    }
]

# AI-generated response to validate
response = "Tork was founded in 2024 in Sydney and supports Python and Node.js."

# Validate grounding
result = client.rag.validate(
    response=response,
    sources=sources,
    threshold=0.8  # Minimum grounding score
)

print(f"Grounded: {result.is_grounded}")
print(f"Grounding score: {result.score}")

for claim in result.claims:
    print(f"  - '{claim.text}': {claim.status} (source: {claim.source_url})")

Claim-Level Analysis

Get detailed analysis of each claim in the response:

json
{
  "is_grounded": true,
  "score": 0.92,
  "claims": [
    {
      "text": "Tork was founded in 2024",
      "status": "supported",
      "confidence": 0.98,
      "source_url": "https://docs.tork.network/about",
      "source_excerpt": "Tork was founded in 2024..."
    },
    {
      "text": "headquartered in Sydney",
      "status": "supported",
      "confidence": 0.95,
      "source_url": "https://docs.tork.network/about",
      "source_excerpt": "...is headquartered in Sydney."
    },
    {
      "text": "supports Python and Node.js",
      "status": "supported",
      "confidence": 0.88,
      "source_url": "https://docs.tork.network/installation",
      "source_excerpt": "...supports Python 3.8+ and Node.js 18+."
    }
  ],
  "unsupported_claims": []
}

RAG Policies

Enforce RAG grounding through policies:

yaml
# policy.yaml
policies:
  - name: require-grounded-responses
    description: Block responses with unsupported claims
    trigger: output
    action: BLOCK
    conditions:
      - type: rag_grounding_score
        operator: less_than
        value: 0.7
    message: "Response contains unsupported claims"

  - name: require-citations
    description: Ensure all factual claims have citations
    trigger: output
    action: WARN
    conditions:
      - type: missing_citations
        min_claims: 1
    webhook: "https://hooks.slack.com/..."

Best Practice: Always validate RAG responses before presenting them to users, especially for factual or compliance-sensitive content.

Documentation

Learn to integrate TORK

Upgrade Plan

Current: free

Support

Get help from our team