π‘οΈ "ESLint + Pytest" for AI responses β Catch LLM mistakes before they reach production.
Schema validation, content linting, and professional reports for any LLM.
pip install llm-contractsLLMs are fluent, confident, and totally wrong just often enough to break your app.
- Air Canada's chatbot promised non-existent bereavement fares β Legal action
- CNET's AI published financial advice with wrong interest rates β Public corrections
- ChatGPT lawyer submitted fake legal citations in court β Professional sanctions
llm-contracts validates every AI response before it causes problems.
# Validate AI output against schema
llm-validate output.json --schema schema.yaml
# Generate professional reports
llm-validate output.json --schema schema.yaml --html-report report.htmlfrom llm_contracts import contracts
# Validate output against schema
result = contracts.validate(data, "schema.yaml")
if not result.is_valid:
print("AI failed validation:")
for error in result.errors:
print(f" - {error}")
# Generate reports
contracts.generate_report(result, "report.html", "schema.yaml", format="html")- Schema Validation β Ensure proper JSON/YAML structure and data types
- Content Linting β Check keywords, tone, word count, patterns, quality rules
- Professional Reports β Beautiful HTML and Markdown validation reports
- Framework Agnostic β Works with OpenAI, Anthropic, local models, any LLM
- CLI + Python API β Use in scripts or integrate into applications
- Zero Vendor Lock-in β Pure validation logic, no external API calls required
schema:
title:
type: str
min_length: 10
description:
type: str
min_length: 100
rules:
- keyword_must_include: ["quality", "premium"]
- keyword_must_not_include: ["cheap", "defective"]
- no_placeholder_text: "\\[YOUR_TEXT_HERE\\]"
- word_count_min: 100
- word_count_max: 500Result: Every AI response gets validated before reaching your users. No more silent failures.
- π Complete Documentation & Whitepaper
- π Getting Started Guide
- π‘ Real-World Examples
- π GitHub Source
- π Report Issues
Created by Mohamed Jama - Built for developers shipping AI features in production.
Major Contributors:
- Abdirahman Attila - Frontend web interface, comprehensive documentation website, enhanced testing suite, and Jekyll/GitHub Pages setup
We welcome contributions! See CONTRIBUTING.md for guidelines.
MIT Β© Mohamed Jama - see LICENSE file for details.
I believe developers don't live outside the world β we help shape it.
I stand in full solidarity with the people of Palestine, especially in Gaza, who continue to endure conditions no human should face: siege, displacement, and the systematic erasure of life and dignity.
This is not about politics. It's about humanity.
Silence is not neutrality.
Learn more and support:
- Decolonize Palestine
- Visualizing Palestine
- Medical Aid for Palestinians (MAP)
- Palestine Children's Relief Fund (PCRF)
- Al-Haq β Palestinian Human Rights Org
- UNRWA Emergency Appeal β Gaza
Stop hoping your AI gets it right. Start knowing it does.