No description
Find a file
autocommit b2646a7808
Some checks failed
Publish / publish (push) Failing after 1s
Publish to PyPI / Build and Publish (push) Failing after 40s
deps-upgrade(specific-known): ⬆️ Update dependencies in pyproject.toml to newer versions for security patches and bug fixes
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
2026-04-12 00:22:25 -07:00
.forgejo/workflows chore: initial commit with DRY workflow 2026-01-21 12:49:17 -08:00
dist chore: initial commit with DRY workflow 2026-01-21 12:49:17 -08:00
src/lilith_truth_service chore: initial commit with DRY workflow 2026-01-21 12:49:17 -08:00
pyproject.toml deps-upgrade(specific-known): ⬆️ Update dependencies in pyproject.toml to newer versions for security patches and bug fixes 2026-04-12 00:22:25 -07:00
README.md chore: initial commit with DRY workflow 2026-01-21 12:49:17 -08:00

Truth Validation Service

Content validation against Lilith Platform facts and terminology rules.

Purpose

Ensures all generated content (SEO, marketing, etc.) is:

  • Factually accurate about the platform
  • Uses appropriate terminology
  • Auto-corrects violations before publishing

Quick Start

# Run the service
cd @packages/@ml/truth-service
PYTHONPATH=src uvicorn lilith_truth_service.app:app --port 3002

# Test health
curl http://localhost:3002/health

API Endpoints

Validate Content

POST /api/validate

Request:

{
  "content": "Creators keep 85% of their earnings on our platform.",
  "auto_correct": true
}

Response:

{
  "is_valid": false,
  "issues": [
    {
      "rule_id": "econ-take-rate-wrong",
      "severity": "critical",
      "message": "Incorrect take rate: Creators keep 100% of earnings",
      "actual": "creators keep 85%",
      "correction": "creators keep 100%",
      "auto_correctable": true
    }
  ],
  "total_issues": 1,
  "critical_count": 1,
  "high_count": 0,
  "auto_corrections": 1,
  "corrected_content": "Creators keep 100% of their earnings on our platform."
}

Auto-Correct Content

POST /api/correct

Request:

{
  "content": "Find the best hookers near you."
}

Response:

{
  "original_content": "Find the best hookers near you.",
  "corrected_content": "Find the best sex worker near you.",
  "corrections_applied": 1,
  "issues_fixed": [...]
}

Get Platform Facts

GET /api/facts

Response:

{
  "economics": {
    "commission_rate": "0%",
    "creator_take_rate": "100%",
    "revenue_model": "premium features"
  },
  "competitors": {
    "onlyfans_commission": "20%",
    "chaturbate_commission": "40-50%",
    "fansly_commission": "20%"
  },
  "jurisdiction": {
    "registration": "Iceland",
    "privacy_framework": "GDPR",
    "speech_protection": "Icelandic law"
  },
  "terminology": {
    "preferred_worker": "sex worker",
    "preferred_creator": "creator",
    "preferred_client": "client",
    "forbidden_terms": ["whore", "hooker", "john", "trick"]
  }
}

Validation Rules

Economic Rules (CRITICAL)

Rule ID Pattern Correction
econ-commission-wrong "platform charges X% commission" X → 0
econ-take-rate-wrong "creators keep X%" X → 100

Competitor Rules (HIGH)

Rule ID Pattern Correction
competitor-onlyfans-wrong "OnlyFans takes X%" X → 20

Terminology Rules (MEDIUM)

Forbidden Term Preferred Term
hooker sex worker
whore sex worker
john client
trick client

Severity Levels

Level Meaning Blocks Publishing
CRITICAL Factual errors about platform economics Yes
HIGH Competitor comparison errors Yes
MEDIUM Terminology violations No (corrected)
LOW Style suggestions No

Integration with SEO Service

The SEO service calls truth validation after generating content:

# In seo-service/generator.py
async def generate_full_content(self, request):
    # 1. Generate content with LLM
    content = await self._generate_with_ollama(request)

    # 2. Validate with truth service
    if request.run_validation:
        validation = await self._truth.validate(content.body)

        # 3. Apply corrections if needed
        if validation.corrected_content:
            content.body = validation.corrected_content

    return content, validation

Architecture

┌─────────────────────────────────────────────────────────────────┐
│                    TRUTH SERVICE                                │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  ┌─────────────────────┐    ┌─────────────────────┐           │
│  │   Platform Facts    │    │   Validation Rules  │           │
│  │   (Source of Truth) │    │   (Pattern-based)   │           │
│  └─────────────────────┘    └─────────────────────┘           │
│           │                          │                         │
│           ▼                          ▼                         │
│  ┌─────────────────────────────────────────────────────────┐  │
│  │              PlatformTruthValidator                      │  │
│  │  • validate(content) → ValidationResult                  │  │
│  │  • correct(content) → (corrected, count)                 │  │
│  └─────────────────────────────────────────────────────────┘  │
│                                                                 │
│  ┌─────────────────────────────────────────────────────────┐  │
│  │              LegalLLMValidator (v0.2.0)                  │  │
│  │  • review(content) → LegalReviewResult                   │  │
│  │  • quick_check(content) → bool                           │  │
│  │  Uses: law-llm (7B legal-domain LLM)                     │  │
│  └─────────────────────────────────────────────────────────┘  │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

The service now includes AI-powered legal review using a specialized legal LLM. Unlike platform truth validation, legal issues require human review and are not auto-corrected.

POST /api/legal-review

Request:

{
  "content": "We collect your browsing history to improve ads.",
  "context": "marketing page",
  "min_confidence": 0.5
}

Response:

{
  "content_hash": "a1b2c3d4e5f6g7h8",
  "issues": [
    {
      "id": "abc123",
      "category": "privacy",
      "severity": "high",
      "summary": "GDPR consent notice missing",
      "explanation": "Under GDPR Article 13, users must be informed about data collection.",
      "affected_text": "We collect your browsing history",
      "suggestion": "Add explicit consent mechanism before data collection",
      "confidence": 0.85,
      "status": "pending",
      "reviewed_by": null,
      "review_notes": null
    }
  ],
  "total_issues": 1,
  "pending_review": 1,
  "high_severity_count": 1,
  "model_used": "law-llm",
  "requires_human_review": true
}

Update Issue Status

After human review, update the issue status:

POST /api/legal-review/{content_hash}/update

Request:

{
  "issue_id": "abc123",
  "status": "approved",
  "reviewed_by": "legal@lilith.com",
  "review_notes": "Consent banner is already present on the page"
}

List Pending Reviews

GET /api/legal-review/pending
Category Description
privacy GDPR, data protection
ip Intellectual property, copyright
defamation Libel, slander
contract Contractual language, terms
compliance Regulatory compliance
advertising Truth in advertising
liability Liability disclaimers
jurisdiction Jurisdictional concerns

Model Management

# Pre-load the legal LLM (reduces first request latency)
POST /api/legal-model/load

# Unload to free memory
POST /api/legal-model/unload

Environment Variables

# Path to legal LLM model (default: /mnt/bigdisk/_/models/models/llm/specialized/legal/law-llm.Q8_0.gguf)
LEGAL_LLM_PATH=/path/to/law-llm.gguf

# Pre-load model on service start
PRELOAD_LEGAL_LLM=true

Python Usage

from lilith_truth_service import LegalLLMValidator, LegalCategory

validator = LegalLLMValidator()
await validator.load_model()

# Full review
result = await validator.review(
    "Your content here",
    categories=[LegalCategory.PRIVACY, LegalCategory.COMPLIANCE],
    min_confidence=0.7,
)

# Quick check (True = no obvious issues)
is_ok = await validator.quick_check("Simple content")

Files

truth-service/
├── src/lilith_truth_service/
│   ├── __init__.py         # Package exports
│   ├── __main__.py         # CLI entry point
│   ├── app.py              # FastAPI application
│   ├── models.py           # Pydantic models + PLATFORM_FACTS
│   ├── validator.py        # PlatformTruthValidator
│   └── legal_validator.py  # LegalLLMValidator (uses law-llm)
├── pyproject.toml          # Package config
└── README.md               # This file

Configuration

# Service port (default: 3002)
TRUTH_SERVICE_PORT=3002

# Strict mode - fail on any issue (default: false)
TRUTH_SERVICE_STRICT=false

Usage in Python

from lilith_truth_service import PlatformTruthValidator

validator = PlatformTruthValidator()

# Validate
result = validator.validate("Creators keep 80% of earnings")
print(result.is_valid)  # False
print(result.corrected_content)  # "Creators keep 100% of earnings"

# Get correction count
corrected, count = validator.correct("Platform charges 5% fee")
print(corrected)  # "Platform charges 0% fee"
print(count)  # 1