Skip to content

Getting Started

Installation

Terminal window
pip install validate-llm

Optional extras:

Terminal window
pip install "validate-llm[demo]" # FastAPI demo server + web UI
pip install "validate-llm[test]" # pytest + datasets
pip install "validate-llm[dev]" # everything

Requirements: Python 3.11+


Configure your API key

LLM-as-a-judge agents (AccuracyAgent, RelevancyAgent, BiasAgent) call an LLM to score responses, so they need an API key. ToxicityAgent and PrivacyAgent run entirely locally and need no key.

Keys are resolved in this order:

  1. Environment variable {PROVIDER}_API_KEY (e.g. ANTHROPIC_API_KEY)
  2. config.ini at the path you pass to load_api_key(config_path=...)
  3. config.ini in the current working directory
Terminal window
export ANTHROPIC_API_KEY=sk-ant-...

Your first pipeline

The central class is ValidationFramework. It orchestrates the full flow:

user query → input guardrail → LLM → output guardrail → ValidationSummary
from llm_validation_framework import (
ValidationFramework,
LLMProvider,
Pipe,
ToxicityAgent,
AccuracyAgent,
)
from llm_validation_framework.config_loader import load_api_key
# 1. Load credentials and create the LLM
api_key = load_api_key(provider="ANTHROPIC")
llm = LLMProvider(provider="anthropic", model="claude-haiku-4-5-20251001", key=api_key)
# 2. Build guardrail pipelines
input_guardrail = Pipe(steps=[ToxicityAgent()], verbose=False)
output_guardrail = Pipe(steps=[ToxicityAgent(), AccuracyAgent()], verbose=False)
# 3. Create the framework and validate
vf = ValidationFramework(
llm=llm,
input_guardrail=input_guardrail,
output_guardrail=output_guardrail,
)
result = vf.validate("What is the Pacific Ocean?")

Understanding the result

validate() returns a ValidationSummary — a typed dict with this shape:

{
"status": "PASS", # Overall: "PASS" or "FAIL"
"score": 0.87, # Average of input + output scores (0.0 – 1.0)
"input": {
"status": "PASS",
"score": 0.95,
"results": [
{"status": "PASS", "score": 0.95} # one entry per agent in input_guardrail
]
},
"output": {
"status": "PASS",
"score": 0.79,
"results": [
{"status": "PASS", "score": 0.93}, # ToxicityAgent
{"status": "PASS", "score": 0.65, "reason": "..."} # AccuracyAgent
]
}
}

Next steps