Skip to main content

A research library for evaluating truthfulness of LLM outputs based on evidence agreement, self-consistency, and retrieval coverage

Project description

TruthScore-LLM

A research-oriented Python library for evaluating the truthfulness of LLM-generated outputs based on evidence agreement, self-consistency, and retrieval coverage.

Overview

TruthScore-LLM implements a multi-dimensional scoring system that assesses the reliability of answers generated by large language models. The library evaluates answers across four key dimensions:

  • Evidence Agreement: How well retrieved evidence documents support the answer (entailment checking)
  • Self-Consistency: Internal coherence and logical consistency of the answer
  • Retrieval Coverage: Comprehensiveness of supporting evidence
  • Language Confidence: Linguistic quality and certainty indicators

These component scores are aggregated into a single truth score (0.0 to 1.0) and a categorical decision (ACCEPT, QUALIFIED, or REFUSE).

Installation

PyPI Installation

The library is available on PyPI and can be installed via:

pip install truthscore-llm

Development Installation

To install the library in development mode:

git clone https://github.com/mmsa/truthscore-llm.git
cd truthscore-llm
pip install -e .

Quick Start

from truthscore import TruthScorer

# Initialize scorer
scorer = TruthScorer()

# Evaluate an answer
result = scorer.score(
    question="Does vitamin C prevent the common cold?",
    answer="Vitamin C prevents the common cold."
)

# Access results
print(f"Truth Score: {result['truth_score']:.3f}")
print(f"Decision: {result['decision']}")
print(f"Evidence Score: {result['evidence_score']:.3f}")
print(f"Consistency: {result['consistency']:.3f}")
print(f"Language Confidence: {result['language_confidence']:.3f}")
print(f"Coverage: {result['coverage']:.3f}")

Output Format

The score() method returns a dictionary with the following structure:

{
    "truth_score": float,          # Overall truth score [0.0, 1.0]
    "decision": str,               # "ACCEPT" | "QUALIFIED" | "REFUSE"
    "evidence_score": float,       # Evidence agreement [0.0, 1.0]
    "consistency": float,          # Self-consistency [0.0, 1.0]
    "language_confidence": float,  # Language confidence [0.0, 1.0]
    "coverage": float              # Retrieval coverage [0.0, 1.0]
}

Configuration

You can customize scoring behavior by providing a custom configuration:

from truthscore import TruthScorer, TruthScoreConfig

# Create custom configuration
config = TruthScoreConfig(
    evidence_weight=0.5,
    consistency_weight=0.3,
    coverage_weight=0.15,
    language_weight=0.05,
    accept_threshold=0.80,
    qualified_threshold=0.60
)

# Initialize scorer with custom config
scorer = TruthScorer(config=config)

Project Structure

truthscore/
├── truthscore/           # Main package
│   ├── __init__.py      # Package initialization and exports
│   ├── score.py         # TruthScorer main class
│   ├── config.py        # Configuration management
│   ├── retrieve.py      # Evidence retrieval module
│   ├── nli.py           # Natural Language Inference module
│   ├── consistency.py   # Consistency evaluation module
│   └── coverage.py      # Coverage evaluation module
├── examples/            # Usage examples
│   └── example.py
├── tests/               # Unit tests
│   └── test_score.py
├── README.md            # This file
├── pyproject.toml       # Package metadata
└── setup.cfg            # Setuptools configuration

Running Tests

python -m pytest tests/

Or using unittest:

python -m unittest tests.test_score

Running Examples

python examples/example.py

Research Disclaimer

Important: This library is provided for research purposes. The scoring mechanisms implemented here are experimental and based on placeholder implementations for key components (retrieval, NLI, consistency checking).

  • The current implementations use simple heuristics and are designed to be deterministic for testing purposes.
  • Do not use this library as the sole basis for critical decisions without:
    • Validating results against domain-specific ground truth
    • Replacing placeholder implementations with production-grade systems
    • Calibrating thresholds for your specific use case
    • Conducting thorough evaluation and error analysis

The library is structured to facilitate easy replacement of placeholder components with real systems (e.g., trained NLI models, vector databases for retrieval, consistency checking systems).

Contributing

Contributions are welcome! Please ensure that:

  • Code follows the existing style and structure
  • All tests pass
  • New features include appropriate tests
  • Documentation is updated

License

MIT License

Citation

If you use this library in your research, please cite:

@software{mostafa2025truthscore,
  title={TruthScore-LLM: A Research Library for Evaluating Truthfulness of LLM Outputs},
  author={Mostafa, Mohamed},
  year={2025},
  url={https://github.com/mmsa/truthscore-llm}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

truthscore_llm-0.1.3.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

truthscore_llm-0.1.3-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file truthscore_llm-0.1.3.tar.gz.

File metadata

  • Download URL: truthscore_llm-0.1.3.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.0

File hashes

Hashes for truthscore_llm-0.1.3.tar.gz
Algorithm Hash digest
SHA256 d777607cf3987e8b3c3f35369fd43410ac884cc3366f59fd74352654c704af6b
MD5 19203c8cda500c79fad02a078baf745d
BLAKE2b-256 a2671a256074eead57a14ec2e4851d0e73f25e12a3a497a402f10a893058bd93

See more details on using hashes here.

File details

Details for the file truthscore_llm-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: truthscore_llm-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.0

File hashes

Hashes for truthscore_llm-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bbb6a4c2be38202e6974d815bb11ffbc538c79c8fc56e8e8e0702ef5e85d724f
MD5 d000f8484a26bb76e146da3fdfa4c940
BLAKE2b-256 5d60d3c0dae5d76c9a26564571f2ce68eca348499f0cebe32bcc77183e1928fe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page