Skip to main content
TrustifAI evaluates LLM and RAG responses through four trust signals — evidence coverage, epistemic consistency, semantic drift, and source diversity — and combines them into a single weighted Trust Score. This guide walks you through installing the SDK, configuring your environment, scoring a RAG response, and visualizing the reasoning behind the score.
1

Install TrustifAI

TrustifAI requires Python 3.10 or later. Install it from PyPI:
For full installation options including tracing and test extras, see the Installation guide.
2

Set up your environment

TrustifAI uses LiteLLM to call LLMs and embedding models, so you configure it by setting the appropriate API key for your provider. Create a .env file in your project root:
.env
Then point your config_file.yaml at the model you want to use:
config_file.yaml
3

Score a RAG response

Use MetricContext to bundle your query, answer, and retrieved documents, then call get_trust_score():
The result dictionary contains the aggregated score (0.0–1.0), a human-readable label (RELIABLE, ACCEPTABLE (WITH CAUTION), or UNRELIABLE), and a details dictionary with individual metric scores.
4

Generate with real-time confidence scoring

For online evaluation — where you want confidence alongside generation — use the generate() method. It calls your configured LLM with logprobs enabled and returns a confidence score derived from token log probabilities:
Confidence scoring relies on token log probabilities. Not all models expose logprobs, and poorly calibrated models may produce unreliable confidence estimates. Check your provider’s documentation before relying on this signal in production.
5

Visualize the reasoning graph

TrustifAI builds a directed acyclic graph (DAG) that shows how each metric score flows into the final trust decision. Pass your result to build_reasoning_graph(), then call visualize():
The PyVis output is a physics-based interactive graph where nodes are color-coded by trust level: green for high trust, orange for partial, and red for low trust.

Next steps

Installation

Full installation options including trace and test extras, git clone setup, and all supported provider keys.

Configuration

Tune metric thresholds, adjust score weights, and configure LiteLLM providers.

Core concepts

Understand how each trust signal is computed and combined into the final score.

Custom metrics

Extend TrustifAI with your own evaluation logic using the BaseMetric interface.