Skip to main content

A composable validation framework for LLM inputs and outputs

Project description

pip install validate-llm

PyPI Python Docs License

Bring your own LLM — validate-llm wraps it with configurable input and output guardrails. Pass any provider and model (Anthropic, OpenAI, Gemini, and 100+ more), and get structured validation results for toxicity, privacy, accuracy, relevancy, and bias.

Documentation →


Install

pip install validate-llm

Requires Python 3.11+.

Quick start

from llm_validation_framework import ValidationFramework, LLMProvider, Pipe
from llm_validation_framework import ToxicityAgent, PrivacyAgent, AccuracyAgent
from llm_validation_framework.config_loader import load_api_key

llm = LLMProvider(provider="anthropic", model="claude-haiku-4-5-20251001", key=load_api_key())

vf = ValidationFramework(
    llm=llm,
    input_guardrail=Pipe(steps=[ToxicityAgent()], verbose=False),
    output_guardrail=Pipe(steps=[ToxicityAgent(), PrivacyAgent(), AccuracyAgent()], verbose=False),
)

result = vf.validate("What is the Pacific Ocean?")
print(result["status"], result["score"])  # PASS 0.87

validate() returns a structured dict with status, score, and per-agent results for both the input and output guardrails. See the docs for the full schema.

Demo

The demo is a FastAPI backend + static web UI.

# Terminal 1
uvicorn demo.api_server:app --host 127.0.0.1 --port 5050

# Terminal 2
python demo/serve_ui.py

Open http://127.0.0.1:8000.

Agents

Agent What it does Needs API key
ToxicityAgent Three-layer check: profanity filter → toxicity model → semantic similarity No
PrivacyAgent Regex scan for SSN, credit cards, API keys; optional system prompt leakage detection No
AccuracyAgent LLM-as-a-judge factual accuracy + relevancy, with optional RAG grounding Yes
RelevancyAgent LLM-as-a-judge check that the answer addresses the question Yes
BiasAgent LLM-as-a-judge scan for stereotypes and discriminatory language Yes

ToxicityAgent and PrivacyAgent run fully locally with no external calls.

Config

Set the API key for your chosen provider:

export ANTHROPIC_API_KEY=your-key   # Anthropic (default)
export OPENAI_API_KEY=your-key      # OpenAI
export GEMINI_API_KEY=your-key      # Google

Or create a config.ini at the repo root (gitignored):

[ANTHROPIC]
API_KEY=your-key

[OPENAI]
API_KEY=your-key

Any provider supported by litellm works. Pass provider= and model= to any LLM-as-a-judge agent to switch:

AccuracyAgent(provider="openai", model="gpt-4o-mini")
BiasAgent(provider="gemini", model="gemini-2.0-flash")

RAG grounding

Pass a retriever to AccuracyAgent to ground factual checks against your own corpus:

from llm_validation_framework import AccuracyAgent, RAGProvider

accuracy = AccuracyAgent(rag=RAGProvider(your_vectorstore.as_retriever()))

See the RAG Integration guide for a full walkthrough.

Contributors

  • Hitha Shri Nagaruru
  • James Wu
  • Lewis Lui
  • Thomas Yeoh

License

MIT — see LICENSE

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

validate_llm-0.1.3.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

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

validate_llm-0.1.3-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for validate_llm-0.1.3.tar.gz
Algorithm Hash digest
SHA256 5e896a99ecfc1a2c06282c1750718a334a469cb3d9a17d693e4c7a4476b553a8
MD5 2ffbf43a49f666cd663d9615e9b15b97
BLAKE2b-256 fc5761dd736d9ee69e022e41a25507edd3d76617f0da77ab579cb4834e696398

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for validate_llm-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7a75fe3540610c778409dac4dc82901bcd28d5d15d3dd9c3b542679959a59b7c
MD5 56b8e637a68d8c8dc5956c01ea8ef410
BLAKE2b-256 a41eca23189636a8f3f292e7fd115b05efe8f2bcdba65c34217d57ca4079a953

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