Catch AI-generated code mistakes before they cause problems
Project description
🤖 AI Code Validator
Catch AI-generated code mistakes before they cause problems.
A CLI tool that analyzes AI-generated code for hallucinations, security vulnerabilities, and outdated patterns. Get a confidence score before you commit!
🎯 The Problem
66% of developers are frustrated with AI-generated code that's "almost right, but not quite"
45% say debugging AI code is more time-consuming than writing it themselves
20% of AI-generated code suggests non-existent packages (creating "slopsquatting" security risks)
62% of AI code contains security vulnerabilities, even from the latest models
AI Code Validator solves this by automatically detecting:
- 🔍 Hallucinated functions & APIs that don't actually exist
- 📦 Fake dependencies before you
pip installornpm installthem - 🔒 Security vulnerabilities like SQL injection, XSS, and command injection
- ⚠️ Missing input validation (AI's #1 mistake)
- 📅 Outdated patterns from old training data
- 🔑 Hardcoded secrets that shouldn't be in code
⚡ Quick Start
Installation
pip install ai-code-validator
Basic Usage
# Check a single file
aivalidate check myfile.py
# Check entire directory
aivalidate check src/
# Check with JSON output (for CI/CD)
aivalidate check . --format json
# Install git pre-commit hook
aivalidate install-hook
📊 Example Output
==================================================================
🤖 AI CODE VALIDATOR - RESULTS
==================================================================
Confidence Score: 67/100 (FAIR)
Total Issues: 5
Critical: 2 | High: 1 | Medium: 1 | Low: 1
Recommendation:
⚠️ CRITICAL: Hallucinated dependencies detected! Do NOT install these packages.
==================================================================
🚨 CRITICAL ISSUES (2)
==================================================================
[HALLUCINATED_DEPENDENCY]
File: app.py:3
Package "ai-utils-helper" does not exist on PyPI
💡 Suggestion: AI may have hallucinated this package. This creates a "slopsquatting" security risk.
[SQL_INJECTION]
File: database.py:45
Potential SQL injection: String concatenation in SQL query
💡 Suggestion: Use parameterized queries or prepared statements instead
==================================================================
⚠️ HIGH SEVERITY ISSUES (1)
==================================================================
[MISSING_INPUT_VALIDATION]
File: api.py:23
User input without validation detected
💡 Suggestion: AI often omits input validation. Add validation before using user input.
✨ Features
🔍 AI Hallucination Detection
- Detects non-existent functions and methods
- Identifies fake API endpoints
- Spots missing call sites and dependencies
📦 Dependency Validation
- Checks if packages exist on PyPI, npm, etc.
- Prevents "slopsquatting" attacks
- Validates imports in real-time
🔒 Security Scanning
- SQL injection detection
- XSS vulnerability checks
- Command injection patterns
- Hardcoded secrets detection
- Missing input validation (AI's most common mistake)
📊 Confidence Scoring
- 0-100 score based on issue severity
- Clear ratings: EXCELLENT → CRITICAL
- Actionable recommendations
🎨 Beautiful Output
- Color-coded severity levels
- Clear issue descriptions
- Helpful suggestions for fixes
- JSON output for CI/CD integration
🔧 Git Integration
- One-command pre-commit hook installation
- Automatic validation on every commit
- Only checks staged files
🚀 Usage Examples
Basic File Checking
# Single file
aivalidate check app.py
# Multiple files
aivalidate check app.py utils.py models.py
# Entire directory (recursively)
aivalidate check src/
# Current directory
aivalidate check .
Filtering by Severity
# Only critical issues
aivalidate check . --severity critical
# Critical and high only
aivalidate check . --severity high
# All issues (default)
aivalidate check . --severity all
Output Formats
# Human-readable colored output (default)
aivalidate check .
# JSON output for parsing
aivalidate check . --format json
Speed Optimization
# Skip dependency checking (faster, but less thorough)
aivalidate check . --no-deps
Git Integration
# Install pre-commit hook
aivalidate install-hook
# Now runs automatically on git commit!
# To bypass (not recommended):
git commit --no-verify
🏗️ How It Works
AI Code Validator uses a multi-layer analysis approach:
- AST Parsing - Analyzes code structure using Abstract Syntax Trees
- Pattern Matching - Detects common AI hallucination patterns
- Dependency Verification - Checks package registries (PyPI, npm) in real-time
- Security Analysis - Scans for OWASP Top 10 vulnerabilities
- Scoring Algorithm - Calculates confidence score with severity weighting
- Smart Reporting - Groups and prioritizes issues for quick fixes
Supported Languages
- ✅ Python (
.py) - ✅ JavaScript (
.js,.jsx) - ✅ TypeScript (
.ts,.tsx) - ✅ Java (
.java) - ✅ Kotlin (
.kt) - 🚧 More coming soon!
🔗 CI/CD Integration
GitHub Actions
name: AI Code Validation
on: [push, pull_request]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install AI Code Validator
run: pip install ai-code-validator
- name: Run validation
run: aivalidate check . --format json --severity high
GitLab CI
ai-validation:
image: python:3.9
script:
- pip install ai-code-validator
- aivalidate check . --format json --severity high
🤝 Contributing
Contributions are welcome! Here's how you can help:
- Report bugs - Open an issue describing the problem
- Suggest features - What would make this tool more useful?
- Add language support - Help us support more languages
- Improve detection - Add more AI hallucination patterns
- Write documentation - Help others use the tool
Development Setup
# Clone the repository
git clone https://github.com/ashishmahawal/ai-code-validator.git
cd ai-code-validator
# Initialize development environment (installs deps + pre-commit hooks)
make init
# Or manually:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements-dev.txt
pip install -e .
pre-commit install
# Run tests
make test
# or: pytest tests/
# Run tests with coverage
make test-cov
# Run linters
make lint
# Format code
make format
See CONTRIBUTING.md for detailed contribution guidelines.
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
⭐ Support
If this tool saved you from debugging AI-generated code, give it a star! ⭐
It helps others discover the project and motivates continued development.
🙏 Acknowledgments
Built based on research into AI code generation issues:
- METR Study on AI Developer Productivity
- Endor Labs Security Research
- CSET Georgetown Cybersecurity Research
📚 Learn More
- Research: Why do AI tools generate buggy code? Read our blog post
- Best Practices: Using AI Coding Tools Safely
- FAQ: Frequently Asked Questions
Made with ❤️ by developers frustrated with AI hallucinations
Don't let AI fool you. Validate before you commit!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ai_code_validator-0.1.0.tar.gz.
File metadata
- Download URL: ai_code_validator-0.1.0.tar.gz
- Upload date:
- Size: 23.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04f22d738892f8cd91e299722fed6f863b3ffc653d3d7d759c2faa670984083b
|
|
| MD5 |
53c9857478eaea3fe47b0a954c654a0e
|
|
| BLAKE2b-256 |
82bc4bad6408a2ece1c35dae6ed421be30e51ca9bea323b380bfea0174292ea9
|
File details
Details for the file ai_code_validator-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ai_code_validator-0.1.0-py3-none-any.whl
- Upload date:
- Size: 18.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
083b61e7fca308b508a824cbb0419597bc6bdd79ad3f9ddbeeea9d7038bb514a
|
|
| MD5 |
768546cb9c282b655d704f7f9d23bb3a
|
|
| BLAKE2b-256 |
8e6cce861ec1c1a8393accf125d7257dd79d3f955edea3ccd97b36ea1300c031
|