llm-contracts
🛡️ "ESLint + Pytest" for AI responses — Catch LLM mistakes before they reach production.
Schema validation, content linting, and professional reports for any LLM.
📦 Install
pip install llm-contracts
⚡ Why llm-contracts?
LLMs 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.
🚀 Quick Start
CLI
# 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.html
Python API
from 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")
✅ Key Features
- 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
📋 Example Schema
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: 500
Result: Every AI response gets validated before reaching your users. No more silent failures.
📚 Documentation & Links
- 📖 Complete Documentation & Whitepaper
- 🚀 Getting Started Guide
- 💡 Real-World Examples
- 🛠 GitHub Source
- 🐛 Report Issues
🤝 Contributors
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.
🏷 License
MIT © Mohamed Jama - see LICENSE file for details.
Stop hoping your AI gets it right. Start knowing it does.
Metadata
Release files for llm-contracts 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| llm_contracts-1.0.0.tar.gz | 36.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llm_contracts-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 57.0 kB
Release files / llm_contracts-1.0.0.tar.gz
| Download URL | llm_contracts-1.0.0.tar.gz |
|---|---|
| Size | 36.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
867e7b6c559619554e20400deadf09bb8ff046b23b876f44f4a2a0403eca5cc5
|
|
BLAKE2b-256 checksum How to use checksums |
71b781c694be887392b0cba0f7b1c0534a6a15cc9da380cadd4462703a9a1d81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.18
|
Release files / llm_contracts-1.0.0-py3-none-any.whl
| Download URL | llm_contracts-1.0.0-py3-none-any.whl |
|---|---|
| Size | 20.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1041f6cb3d8f71154eefabc711559bb3940958662f67bda2e32fee9d484415ea
|
|
BLAKE2b-256 checksum How to use checksums |
5f43e43013078e936f4b94aa1f31716a08695617347471c7af255166baf98a2f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.18
|
Security for llm-contracts 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.