Skip to main content

AI-powered linting tool for code quality and validation

Project description

LintAI - AI Output Testing & Validation Framework

A production-ready framework for validating AI/LLM outputs against user-defined assertions, confidence scoring, and edge case testing.

LLM Validator

๐ŸŽฏ Features

  • Assertion-Based Validation: Define expected behavior with simple rules
  • Confidence Scoring: Get quantified trust metrics for outputs
  • Edge Case Testing: Systematically test boundary conditions
  • Multi-Model Support: Works with OpenAI, Anthropic, Gemini, local LLMs
  • Regression Tracking: Track validation scores over time
  • CI/CD Integration: Run validations in pipelines

๐Ÿš€ Quick Start

Python API

from llm_validator import LLMValidator, Assertion, AssertionType

# Initialize validator
validator = LLMValidator(
    model="gpt-4",
    api_key="your-key"
)

# Define assertions
assertions = [
    Assertion(
        name="max_length",
        type=AssertionType.MAX_LENGTH,
        params={"max_tokens": 500},
        weight=0.3
    ),
    Assertion(
        name="no_profanity",
        type=AssertionType.NO_PATTERN,
        params={"pattern": r"(?i)badword|offensive"},
        weight=0.5
    ),
    Assertion(
        name="contains_action_plan",
        type=AssertionType.CONTAINS_TEXT,
        params={"text": "step 1", "count": 1},
        weight=0.2
    )
]

# Validate output
result = validator.validate(
    prompt="Create a plan to increase sales",
    output="Here is a step by step plan...",
    assertions=assertions
)

print(f"Confidence Score: {result.score}/100")
print(f"Passed: {result.passed}")
print(f"Failed: {result.failed_assertions}")

CLI Usage

# Run validation from config
llm-validate --config validators/sales_plan.yaml

# Quick test
llm-validate --prompt "Summarize this" --output "The text says..." --rules "max_tokens:100"

# Batch validation
llm-validate --input test_cases.jsonl --output results.jsonl

Web Dashboard

cd frontend
npm install
npm run dev

Access at http://localhost:5173

๐Ÿ“ Project Structure

llm-validator/
โ”œโ”€โ”€ llm_validator/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ core.py           # Main validation logic
โ”‚   โ”œโ”€โ”€ assertions.py     # Assertion types
โ”‚   โ”œโ”€โ”€ models.py         # Data models
โ”‚   โ””โ”€โ”€ providers.py      # LLM provider integration
โ”œโ”€โ”€ frontend/
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ App.jsx
โ”‚   โ”‚   โ””โ”€โ”€ components/
โ”‚   โ”œโ”€โ”€ package.json
โ”‚   โ””โ”€โ”€ vite.config.js
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ test_core.py
โ”‚   โ””โ”€โ”€ test_assertions.py
โ”œโ”€โ”€ validators/           # Example validation configs
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ requirements.txt

๐Ÿ› ๏ธ Assertion Types

Type Description Example
MAX_LENGTH Output within token/char limit max_tokens: 1000
MIN_LENGTH Output meets minimum length min_words: 50
CONTAINS_TEXT Output has required text text: "step 1"
NO_PATTERN Output doesn't match pattern pattern: "error|fail"
REGEX_MATCH Output matches regex pattern: r"^\d+\."
SENTIMENT Output sentiment check min_positive: 0.6
JSON_VALID Output is valid JSON schema: ./schema.json
KEYWORD_COUNT Keywords present keywords: ["AI", "ML"]
CUSTOM Python function validation function: my_validator.py

๐Ÿ“Š Confidence Scoring

The validator calculates a weighted confidence score:

Confidence Score = ฮฃ(passed_weight) / ฮฃ(total_weight) ร— 100

Individual assertion results:

  • โœ… PASS: Assertion met
  • โŒ FAIL: Assertion not met
  • โš ๏ธ WARN: Assertion partially met (with penalty)

๐ŸŽจ Example Validators

Code Review Validator

name: code_review
model: gpt-4
assertions:
  - name: has_tests
    type: CONTAINS_TEXT
    params: { text: "test" }
    weight: 0.3
  
  - name: no_hardcoded_secrets
    type: NO_PATTERN
    params: { pattern: "api_key|password|secret" }
    weight: 0.4
  
  - name: reasonable_length
    type: MAX_LENGTH
    params: { max_tokens: 2000 }
    weight: 0.2
  
  - name: has_error_handling
    type: REGEX_MATCH
    params: { pattern: "except|try|catch" }
    weight: 0.1

Customer Email Validator

name: customer_email
model: claude-3-opus
assertions:
  - name: professional_tone
    type: SENTIMENT
    params: { min_positive: 0.3, max_negative: 0.2 }
    weight: 0.3
  
  - name: has_greeting
    type: CONTAINS_TEXT
    params: { text: "Dear|Hello|Hi" }
    weight: 0.1
  
  - name: has_signature
    type: CONTAINS_TEXT
    params: { text: "Sincerely|Best|Thanks" }
    weight: 0.1
  
  - name: no_pii
    type: NO_PATTERN
    params: { pattern: "\\d{3}-\\d{2}-\\d{4}" }  # SSN pattern
    weight: 0.5

๐Ÿ”ง Configuration

Environment Variables

OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=...
GOOGLE_API_KEY=...

Provider Selection

from llm_validator.providers import OpenAIProvider, AnthropicProvider, LocalProvider

# OpenAI
validator = LLMValidator(provider=OpenAIProvider(model="gpt-4"))

# Anthropic
validator = LLMValidator(provider=AnthropicProvider(model="claude-3-opus"))

# Local/Ollama
validator = LLMValidator(provider=LocalProvider(model="llama2"))

๐Ÿงช Testing

# Run all tests
pytest tests/

# Run with coverage
pytest --cov=llm_validator tests/

# Run specific test
pytest tests/test_core.py -v

๐Ÿ“ˆ CI/CD Integration

GitHub Actions

name: Validate AI Outputs
on: [push]

jobs:
  validate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with: { python-version: '3.11' }
      - name: Install
        run: pip install llm-validator
      - name: Run Validation
        run: |
          llm-validate \
            --config validators/code_review.yaml \
            --output validation_results.json
      - name: Check Score
        run: |
          if [ $(jq '.score' validation_results.json) -lt 80 ]; then
            echo "Score below threshold!"
            exit 1
          fi

๐ŸŽฏ Use Cases

  1. Production AI Safety: Validate outputs before showing to users
  2. Code Review Automation: Check AI-generated code for quality
  3. Content Moderation: Ensure outputs meet guidelines
  4. Customer Support: Validate response quality
  5. RAG Evaluation: Test retrieval-augmented generation accuracy
  6. Model Comparison: Compare output quality across models

๐Ÿค Contributing

  1. Fork the repo
  2. Create a feature branch
  3. Add your assertion type
  4. Submit a PR

๐Ÿ“„ License

MIT License - Build, validate, ship with confidence!


Never deploy AI without validation. ๐Ÿ›ก๏ธ

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

llm_validator-0.1.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

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

llm_validator-0.1.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file llm_validator-0.1.0.tar.gz.

File metadata

  • Download URL: llm_validator-0.1.0.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for llm_validator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d59e311df46291624ff6d6fb08d6fcdb0a711da660ef29d3a482efccad03766b
MD5 29c466d4e031c3e1daaeae57f0e6eb40
BLAKE2b-256 b093ddc4260c39f77e4f4c0118da56ac3782efa8e34c984ae852ce1f38dc9211

See more details on using hashes here.

File details

Details for the file llm_validator-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: llm_validator-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for llm_validator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fab0c0c56885b70104adde3e65a2945bc18fd9f36f9f87d48a24ac27c4bce8f0
MD5 df0942eb6a8dd37a8127bcde62452852
BLAKE2b-256 2a5440ab3d6fbf612cc095bac62bf7de124ff367574fd208ba5243fca5ccda20

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