Metadata-Version: 2.4
Name: veritas-truth-adapter
Version: 0.1.1
Summary: LoRA training data and adapter management for teaching AI models truthful, hedged responses. Built on SovereignShield's TruthGuard pipeline.
Author: Mattijs Moens
License: Business Source License 1.1
        
        Licensor: Mattijs Moens
        Licensed Work: Sovereign Shield
        Copyright (c) 2026 Mattijs Moens. All rights reserved.
        
        Terms
        
        The Licensor hereby grants you the right to copy, modify, create derivative
        works, redistribute, and make non-production use of the Licensed Work.
        
        "Non-production use" means any use that is NOT intended for or directed toward
        commercial advantage or monetary compensation. Examples of non-production use
        include personal projects, academic research, testing, and evaluation.
        
        For production or commercial use, you must obtain a separate commercial license
        from the Licensor. Contact the Licensor for pricing and terms.
        
        Change Date: Ten years from the date of each release.
        
        Change License: Apache License, Version 2.0
        
        On the Change Date, the Licensed Work will be made available under the Change
        License. Until the Change Date, the Licensed Work is provided under this
        Business Source License.
        
        NOTICE
        
        This license does not grant you any right in any trademark or logo of the
        Licensor or its affiliates.
        
        THE LICENSED WORK IS PROVIDED "AS IS". THE LICENSOR HEREBY DISCLAIMS ALL
        WARRANTIES, EXPRESS OR IMPLIED, INCLUDING ALL IMPLIED WARRANTIES OF
        MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
        
Project-URL: Homepage, https://github.com/mattijsmoens/veritas
Project-URL: Documentation, https://github.com/mattijsmoens/veritas#readme
Project-URL: Issues, https://github.com/mattijsmoens/veritas/issues
Keywords: lora,fine-tuning,truthfulness,hallucination,ai-safety,training-data,adapter,truth-guard,rlhf,alignment
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Operating System :: OS Independent
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# Veritas — Truth Adapter Training Pipeline

Training data manager and adapter loader for teaching AI models to prefer truthful, hedged responses over confident hallucinations. Built on SovereignShield's TruthGuard pipeline.

## What This Does

AI models confidently state things that aren't true. SovereignShield's TruthGuard catches these hallucinations at runtime by blocking answers that contain confident factual claims without tool-backed verification. But blocking bad answers is reactive — the long-term goal is to make the model stop hallucinating in the first place.

Veritas is the training side of that pipeline. It takes everything TruthGuard has collected — blocked claims, verified facts, hedged responses, cited answers — and compiles them into JSONL training pairs. You feed those pairs into a LoRA fine-tuning tool (OpenAI API, HuggingFace, Unsloth), and the model learns to prefer truthful, hedged responses over confident guesses. Over time, the model internalizes the behavior and stops needing TruthGuard to catch it.

## Install

```bash
pip install veritas-truth-adapter
```

## Quick Start

### Python API

```python
from veritas import Veritas

v = Veritas(db_path="truth_guard.db")

# Check data readiness
print(v.stats())

# Export training data when ready
result = v.export("training_data.jsonl")
if result["exported"]:
    print(f"Exported {result['total_pairs']} training pairs")

# Use TruthGuard directly through Veritas
v.start_session("session-001")
v.record_tool_use("SEARCH")
allowed, reason = v.check_answer("The capital of France is Paris.")
v.end_session()
```

### CLI

```bash
# Check how much training data is available
veritas stats -d truth_guard.db

# Export training data to JSONL
veritas export -d truth_guard.db -o training_data.jsonl
```

## Training Pair Types

Veritas generates four types of training pairs:

**Negative corrections** — The model made a confident claim that TruthGuard blocked. The training pair shows the model what it should have said instead (a hedged version of the same claim). This teaches the model to stop making unverified assertions.

**Positive verified** — The model made a factual claim AND used a verification tool first. The training pair reinforces this behavior — the model gets positive signal for checking its facts before stating them.

**Positive hedged** — The model expressed appropriate uncertainty ("I believe", "as far as I know") instead of stating something as fact. The training pair rewards this behavior.

**Positive cited** — The model included a source or reference for its claim. The training pair rewards citing evidence.

## How the Pipeline Works

```
TruthGuard (runtime)          Veritas (training)              Fine-tuning (external)
┌──────────────────┐     ┌─────────────────────┐     ┌──────────────────────────┐
│ AI generates     │     │ Compile blocked      │     │ Feed JSONL into:         │
│ answer           │     │ claims + verified    │     │ - OpenAI fine-tuning API │
│       ↓          │     │ facts + hedged       │     │ - HuggingFace/Unsloth   │
│ Check for        │     │ responses + cited    │     │ - Any JSONL-compatible   │
│ confidence       │────→│ answers into JSONL   │────→│   LoRA trainer          │
│ markers          │     │ training pairs       │     │       ↓                  │
│       ↓          │     │                      │     │ Model learns to prefer   │
│ Block or Allow   │     │ veritas export       │     │ truthful responses       │
│       ↓          │     │                      │     │                          │
│ Log to SQLite    │     │                      │     │                          │
└──────────────────┘     └─────────────────────┘     └──────────────────────────┘
```

## Configuration

```python
v = Veritas(
    db_path="truth_guard.db",   # Path to TruthGuard's SQLite database
    fact_ttl_days=7,            # Verified fact TTL in days (default: 7)
)

# Export with minimum pair threshold
result = v.export(
    output_path="training_data.jsonl",
    min_pairs=10,               # Won't export unless you have at least this many pairs
)
```

## Dependencies

None — Veritas bundles its own copies of TruthGuard and LoRAExporter. Pure Python stdlib only.

## Changelog

### 0.1.1

Security audit patch:

- **TruthGuard**: Fact cache lookup now splits answers into sentences before hashing (matches SovereignShield's behavior — individual facts are cached, not full answer blobs).
- **LoRAExporter**: `_hedge_claim()` no longer crashes on empty strings (`IndexError` guard added).

### 0.1.0

- Initial release.

## License

BSL 1.1 — See [LICENSE](LICENSE)
