Skip to main content

Validate AI-generated code for security vulnerabilities, hallucinations, and logic errors

Project description

๐Ÿ›ก๏ธ AI Code Trust Validator

License: MIT Python 3.8+ GitHub stars GitHub forks Docker VS Code JetBrains

Trust your AI-generated code before shipping to production.

The complete quality gate for AI-assisted development

Installation โ€ข Quick Start โ€ข Features โ€ข CLI Reference โ€ข Documentation


๐ŸŽฏ The Problem

84% of developers use AI coding tools. Only 29% trust the output. (Stack Overflow 2025)

AI writes code fast, but that code often contains:

  • ๐Ÿ”“ Security vulnerabilities โ€” SQL injection, hardcoded secrets, command injection
  • ๐ŸŽญ Hallucinations โ€” Fake imports, invented functions, imaginary APIs
  • ๐Ÿ› Logic errors โ€” Unreachable code, infinite loops, dead branches
  • ๐Ÿ“‰ Technical debt โ€” Missing docs, poor naming, deep nesting
  • ๐Ÿ”— Dependency issues โ€” Circular imports, missing modules, unused code

You can't ship what you can't trust.


โœจ Features

Category Features
๐Ÿ” Analysis Security scanning, Hallucination detection, Logic validation, Best practices
๐ŸŒ Multi-Language Python, JavaScript, TypeScript support
๐Ÿค– AI Auto-Fix LLM-powered fixes (OpenAI, Anthropic, Ollama)
๐Ÿ“Š Reports JSON, HTML (beautiful dashboard), SARIF (GitHub Security), PDF
๐Ÿ”ง Fixes Auto-fix suggestions, Confidence scores, One-click apply
๐Ÿงช Testing Auto-generate pytest tests, Edge case detection, Coverage analysis
๐ŸŒ API REST API server, OpenAPI docs, Batch validation, Webhook support
๐Ÿ‘€ Monitoring File watch mode, Live dashboard, Continuous validation
๐Ÿ“ฆ Multi-file Dependency analysis, Circular dependency detection, Import validation
โšก Performance Intelligent caching, Incremental analysis, ~10,000+ lines/sec
๐Ÿ”Œ Extensible Plugin system, Custom analyzers, Hook system
๐Ÿณ Deployment Docker, Docker Compose, GitHub Action, Pre-commit hooks
๐Ÿ’ป IDE Integration VS Code extension, JetBrains plugin, LSP server
๐Ÿ“ˆ Team Analytics Dashboard, Leaderboards, Trend analysis, Project breakdown

๐Ÿ“ฆ Installation

# From PyPI (recommended)
pip install ai-trust-validator

# With server support
pip install ai-trust-validator[server]

# With all extras
pip install ai-trust-validator[all]

# From source
git clone https://github.com/rudra496/ai-code-trust-validator.git
cd ai-code-trust-validator
pip install -e ".[all]"

# Docker
docker pull ghcr.io/rudra496/ai-code-trust-validator:latest
docker run -v ./code:/code ghcr.io/rudra496/ai-code-trust-validator validate /code

๐Ÿš€ Quick Start

CLI

# Validate a file (Python, JS, or TS)
aitrust validate generated_code.py
aitrust validate src/app.js
aitrust validate src/component.tsx

# Validate directory with minimum score
aitrust validate src/ --min-score 75 --strict

# Generate HTML report
aitrust report src/ --format html --output report.html

# Get fix suggestions
aitrust suggest-fixes buggy_code.py

# AI-powered auto-fix (requires API key)
export OPENAI_API_KEY="sk-..."
aitrust ai-fix file.py --apply

# Generate tests
aitrust generate-tests module.py --output tests/test_module.py

# Start API server
aitrust serve --port 8080

# Watch for changes with live dashboard
aitrust watch src/ --dashboard

# Analyze dependencies
aitrust analyze-deps src/

# Run benchmarks
aitrust benchmark --iterations 100

# View team analytics
aitrust analytics --days 30

# Start LSP server (for IDE integration)
aitrust lsp

# Show supported languages
aitrust languages

Python API

from ai_trust_validator import Validator, Config, MultiLanguageValidator

# Simple validation (auto-detects language)
validator = MultiLanguageValidator()
result = validator.validate("generated_code.py")  # or .js, .ts files

print(f"Trust Score: {result.trust_score}/100")
print(f"Passed: {result.passed}")

for issue in result.critical_issues:
    print(f"[CRITICAL] {issue.message}")
    if issue.suggestion:
        print(f"  ๐Ÿ’ก {issue.suggestion}")

# With custom config
config = Config(min_score=80, strict_mode=True)
validator = Validator(config)
result = validator.validate_code(code_string)

# Multi-file analysis
from ai_trust_validator import MultiFileAnalyzer
analyzer = MultiFileAnalyzer(validator)
result = analyzer.analyze_directory("src/")
print(f"Circular deps: {result.circular_dependencies}")

# Team analytics
from ai_trust_validator import AnalyticsDB
db = AnalyticsDB()
db.record_validation("file.py", result, user="dev1", project="myapp")
stats = db.get_stats(days=30)
print(f"Team avg: {stats.average_score}")

๐ŸŒ JavaScript/TypeScript Support

The validator supports JavaScript and TypeScript files with comprehensive analysis:

Supported File Types

Language Extensions Analysis Type
JavaScript .js, .mjs, .cjs, .jsx Pattern-based analysis
TypeScript .ts, .tsx, .mts JS + type checking

Security Checks for JS/TS

  • eval(), new Function() - Code injection risks
  • innerHTML, outerHTML - XSS vulnerabilities
  • document.write() - XSS and DOM manipulation risks
  • setTimeout(string) - Code injection via strings
  • Prototype pollution (__proto__, constructor.prototype)
  • Hardcoded secrets and API keys
  • child_process.exec() - Command injection
  • @ts-ignore, any type - Type safety bypass

Hallucination Detection

  • Detects hallucinated npm packages
  • Identifies fake/invented functions
  • Checks for placeholder API URLs

Usage

from ai_trust_validator import MultiLanguageValidator, detect_language

validator = MultiLanguageValidator()

# Auto-detects language from file extension
result = validator.validate("src/app.js")
print(f"Language: {detect_language('src/app.js')}")  # 'javascript'
print(f"Trust Score: {result.trust_score}/100")

๐Ÿค– AI-Powered Auto-Fix

Use LLMs to automatically fix detected issues. Supports multiple providers:

Supported Providers

Provider Environment Variable Default Model
OpenAI OPENAI_API_KEY gpt-4o-mini
Anthropic ANTHROPIC_API_KEY claude-3-haiku-20240307
Ollama USE_OLLAMA=true llama3
Custom LLM_BASE_URL + LLM_API_KEY configurable

CLI Usage

# Set your API key
export OPENAI_API_KEY="sk-..."

# Fix a file (shows fixed code)
aitrust ai-fix file.py

# Apply fixes directly (creates .backup file)
aitrust ai-fix file.py --apply

# Fix only security issues
aitrust ai-fix file.py --category security

# Use different provider/model
aitrust ai-fix file.js --provider ollama --model llama3
aitrust ai-fix file.ts --provider anthropic --model claude-3-haiku-20240307

Python API

from ai_trust_validator import Validator, AIAutoFixer, LLMConfig

# Configure LLM
config = LLMConfig(
    provider="openai",
    model="gpt-4o-mini",
    api_key="sk-..."
)

fixer = AIAutoFixer(config)
validator = Validator()

# Validate and fix
code = open("file.py").read()
result = validator.validate(code, is_file=False)
fix_result = fixer.fix(code, result.all_issues, language="python")

if fix_result.success:
    print(f"Fixed with {fix_result.confidence:.0%} confidence")
    print(fix_result.fixed_code)

Quick Fix Function

from ai_trust_validator import ai_fix_code

result = ai_fix_code(
    code,
    issues,
    language="javascript",
    api_key="sk-..."
)
print(result.fixed_code)

๐Ÿ’ป IDE Integration

VS Code

# Install from VS Code Marketplace
# Search for "AI Trust Validator"

# Or install manually
cd vscode-extension
npm install
npm run compile

Features:

  • Real-time diagnostics
  • Trust score in status bar
  • Quick fix suggestions
  • Hover information
  • Auto-validate on save

JetBrains (IntelliJ, PyCharm)

# Install from JetBrains Marketplace
# Search for "AI Trust Validator"

# Or build from source
cd jetbrains-plugin
./gradlew build
# Install the built plugin from build/distributions/

Features:

  • Real-time code analysis with inline warnings
  • Trust score in status bar
  • Tool window with detailed results
  • One-click AI-powered fixes
  • Project-wide validation

LSP Server (Neovim, Emacs, etc.)

# Start LSP server
aitrust lsp

# Configure in your LSP client
# Command: aitrust lsp
# Language: python, javascript, typescript

๐Ÿ“Š Example Output

๐Ÿ” Analyzing: generated_code.py
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“Š TRUST SCORE: 67/100 โš ๏ธ

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Category              Score   Issues               โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Security              72      2 medium, 1 low      โ”‚
โ”‚ Hallucinations        45      3 critical           โ”‚
โ”‚ Logic                 85      1 minor              โ”‚
โ”‚ Best Practices        70      2 warnings           โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿšจ Critical Issues:
  [HALLUCINATION] Line 12: Import 'fancy_lib' does not exist
  [HALLUCINATION] Line 18: Function 'quick_sort_v2' not defined
  [SECURITY] Line 24: Potential SQL injection via f-string

๐Ÿ’ก AI Suggestions:
  โ†’ Replace 'fancy_lib' with 'numpy' or 'pandas'
  โ†’ Use built-in sorted() instead of 'quick_sort_v2'
  โ†’ Use parameterized queries: cursor.execute("... WHERE id = ?", (user_id,))

๐Ÿ”ง CLI Reference

Command Description
aitrust validate <path> Validate code and show trust score
aitrust report <path> Generate detailed report (JSON/HTML/SARIF)
aitrust suggest-fixes <path> Show fix suggestions for issues
aitrust ai-fix <path> Apply AI-powered fixes
aitrust generate-tests <path> Generate pytest tests
aitrust serve Start REST API server
aitrust watch <path> Watch files for changes
aitrust benchmark Run performance benchmarks
aitrust analyze-deps <path> Multi-file dependency analysis
aitrust analytics View team analytics
aitrust cache <action> Manage validation cache
aitrust lsp Start LSP server for IDEs
aitrust languages Show supported languages

๐Ÿณ Docker & Deployment

Docker Compose

version: '3.8'
services:
  validator:
    image: ghcr.io/rudra496/ai-code-trust-validator:latest
    ports:
      - "8080:8080"
    command: serve --port 8080
    volumes:
      - ./code:/code:ro
      - ./.aitrust_cache:/app/.aitrust_cache

GitHub Action

name: AI Code Trust Check
on: [pull_request]

jobs:
  trust-check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Validate AI Code
        uses: rudra496/ai-code-trust-validator@v0.4.0
        with:
          path: 'src/'
          min-score: '75'
          format: 'sarif'

Pre-commit Hook

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/rudra496/ai-code-trust-validator
    rev: v0.4.0
    hooks:
      - id: ai-trust-validator
        args: ['--min-score', '70']

๐Ÿ”Œ Plugin System

Create custom analyzers:

from ai_trust_validator import AnalyzerPlugin, PluginMetadata, Issue

class MyCustomAnalyzer(AnalyzerPlugin):
    @property
    def metadata(self):
        return PluginMetadata(
            name="my_custom",
            version="1.0.0",
            author="You",
            description="Custom analyzer"
        )
    
    def analyze(self, tree, code, context):
        issues = []
        # Your analysis logic
        return issues

# Register
from ai_trust_validator import PluginManager
manager = PluginManager()
manager.register(MyCustomAnalyzer())

๐Ÿ“ˆ Performance

Metric Value
Throughput 10,000+ lines/sec
Avg validation 5-20ms per file
Memory <50MB typical
Cache hit rate 95%+ on re-runs

Run your own benchmarks:

aitrust benchmark --iterations 1000

๐Ÿ—บ๏ธ Roadmap

Completed โœ…

  • Core validation engine
  • Security analyzer
  • Hallucination detector
  • Logic analyzer
  • Best practices checker
  • CLI with rich output
  • JSON/HTML/SARIF reports
  • Fix suggestions
  • Test generation
  • REST API server
  • Docker support
  • GitHub Action
  • Pre-commit hooks
  • Plugin system
  • Multi-file analysis
  • Watch mode
  • Caching system
  • LSP server
  • VS Code extension
  • Web dashboard
  • Team analytics
  • JavaScript/TypeScript support (NEW in v0.4.0)
  • AI-powered auto-fix with LLM integration (NEW in v0.4.0)
  • JetBrains plugin (IntelliJ, PyCharm) (NEW in v0.4.0)

Coming Soon ๐Ÿšง

  • Cloud hosted version

๐Ÿ“Š Statistics

GitHub commit activity GitHub last commit GitHub code size GitHub issues


๐Ÿค Contributing

We welcome contributions! See CONTRIBUTING.md for guidelines.

Ways to help:

  • ๐Ÿ› Report bugs
  • ๐Ÿ’ก Suggest features
  • ๐Ÿ“ Improve documentation
  • ๐Ÿ”ง Submit pull requests
  • โญ Star the repo!

๐Ÿ“„ License

MIT License โ€” use it freely. Just don't blame us if AI breaks production. ๐Ÿ˜‰


๐Ÿ”— Connect with the Creator

Rudra Sarker โ€ข Developer & Researcher

LinkedIn Portfolio GitHub


Built to close the AI trust gap.

If this helped you, consider giving it a โญ โ€” it helps others find it too!

Made with โค๏ธ by Rudra Sarker

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

ai_trust_validator-0.4.0.tar.gz (66.3 kB view details)

Uploaded Source

Built Distribution

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

ai_trust_validator-0.4.0-py3-none-any.whl (71.8 kB view details)

Uploaded Python 3

File details

Details for the file ai_trust_validator-0.4.0.tar.gz.

File metadata

  • Download URL: ai_trust_validator-0.4.0.tar.gz
  • Upload date:
  • Size: 66.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ai_trust_validator-0.4.0.tar.gz
Algorithm Hash digest
SHA256 e9e71408645d53863b5c8789d946a7c886065e26d667aab022b73c4dc56861b9
MD5 d45598f345d687e562a3d2136292daca
BLAKE2b-256 e58e6cb81f5779ae1d9aef370bd0217b021d1f34f430c7c8acc284f6d33d728d

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai_trust_validator-0.4.0.tar.gz:

Publisher: publish.yml on rudra496/ai-code-trust-validator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ai_trust_validator-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ai_trust_validator-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 33bf156042c8f3091e9a0e0bad153e914d26b41b97d4d9298b12f602c85e6f25
MD5 f103847dd774570f33d12d095e3f6d29
BLAKE2b-256 5d77255287fcb43a04b49a61f50890422fb8bff6ae5ef8c525f70c85ff2a19d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai_trust_validator-0.4.0-py3-none-any.whl:

Publisher: publish.yml on rudra496/ai-code-trust-validator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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