Catalog PyPI
Back to packageRELEASE DETAILS

1.0.0

PyPI

ai-code-guard

Industry-grade security scanner for AI-generated code with AST analysis, taint tracking, and comprehensive vulnerability detection

ai-generated-codedevsecopsllm-securityprompt-injectionsastsecuritystatic-analysisvulnerability-scanner
Published16 Jan 2026
Direct dependencies13
Transitive dependenciesNot calculated

README

Version 1.0.0 documentation

🛡️ AI Code Guard Pro

CI Python 3.10+ License: MIT Code style: ruff

Industry-grade security scanner for AI-generated code with AST analysis, taint tracking, and LLM-specific vulnerability detection.

AI coding assistants (GitHub Copilot, Claude, ChatGPT, Cursor) are revolutionizing development—but they can introduce security vulnerabilities that slip past code review. AI Code Guard Pro is a next-generation security scanner specifically designed to catch these issues.

🚀 Key Improvements Over Basic Scanners

FeatureBasic ScannersAI Code Guard Pro
Analysis MethodRegex matchingAST parsing + taint tracking
False PositivesHighReduced via context awareness
Secret DetectionPattern onlyPattern + Shannon entropy
Prompt Injection❌ Not detected✅ Direct + indirect detection
Supply ChainBasicTyposquatting + dependency confusion
Output FormatsLimitedConsole, JSON, SARIF, Markdown
CI/CD IntegrationBasicNative SARIF for GitHub Security

🎯 What It Detects

🔐 Secrets & Credentials

  • API Keys: OpenAI, Anthropic, AWS, GCP, GitHub, Stripe, and 15+ providers
  • Private Keys: RSA, SSH, PGP, EC
  • Database Credentials: Connection strings, passwords
  • High-Entropy Strings: AI placeholder secrets

💉 Injection Vulnerabilities

  • SQL Injection: f-strings, .format(), concatenation in queries
  • Command Injection: os.system, subprocess with shell=True
  • Code Execution: eval(), exec() with user input
  • SSRF: User-controlled URLs in requests

🤖 AI/LLM-Specific Issues

  • Direct Prompt Injection: User input in system prompts
  • Indirect Injection: RAG/retrieval injection risks
  • Unsafe Deserialization: pickle, yaml.load without SafeLoader

📦 Supply Chain Attacks

  • Typosquatting: Similar names to popular packages
  • Dependency Confusion: Internal package name patterns
  • Known Malicious Packages: Database of suspicious packages

📦 Installation

pip install ai-code-guard

Or with development dependencies:

pip install ai-code-guard[dev]

🔧 Quick Start

# Scan a directory
ai-code-guard scan ./src

# Scan with specific output format
ai-code-guard scan ./src --format sarif -o results.sarif

# Quick CI check
ai-code-guard check ./src

# List all rules
ai-code-guard rules

# Create config file
ai-code-guard init

📊 Example Output

🛡️  AI Code Guard Pro v1.0.0
   Scanning ./my-project...

┌─────────────────────────────────────────────────────────────────────┐
│ 🔴 CRITICAL: SQL Injection Vulnerability                            │
├─────────────────────────────────────────────────────────────────────┤
│ 📍 src/db/queries.py:42                                             │
│                                                                     │
│ SQL query constructed using f-string interpolation. User-controlled │
│ data may be interpolated directly into the query, enabling SQL      │
│ injection attacks.                                                  │
│                                                                     │
│ Code: query = f"SELECT * FROM users WHERE id = {user_id}"          │
│                                                                     │
│ ✅ Fix: Use parameterized queries:                                  │
│    cursor.execute('SELECT * FROM users WHERE id = ?', (user_id,))  │
│                                                                     │
│ CWE: CWE-89                                                         │
└─────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────┐
│ 🟠 HIGH: Prompt Injection Vulnerability                             │
├─────────────────────────────────────────────────────────────────────┤
│ 📍 src/api/chat.py:23                                               │
│                                                                     │
│ User input directly embedded in LLM prompt via f-string. Attackers  │
│ can inject malicious instructions to manipulate the AI's behavior.  │
│                                                                     │
│ Code: prompt = f"You are a helper. User says: {user_input}"        │
│                                                                     │
│ ✅ Fix:                                                              │
│ 1. Separate system prompts from user content using message roles    │
│ 2. Sanitize user input (remove control characters, limit length)    │
│ 3. Use structured output formats to detect injection attempts       │
│                                                                     │
│ CWE: CWE-74 | OWASP: LLM01                                          │
└─────────────────────────────────────────────────────────────────────┘

────────────────────────────────────────────────────────────────────────
📊 SUMMARY
────────────────────────────────────────────────────────────────────────
Files scanned    47
Issues found     3
Scan time        127ms

🔴 CRITICAL: 1  🟠 HIGH: 2  🟡 MEDIUM: 0  🔵 LOW: 0
────────────────────────────────────────────────────────────────────────

⚙️ Configuration

Create .ai-code-guard.yaml in your project root:

# Minimum severity to report
min_severity: low  # critical, high, medium, low, info

# Patterns to ignore
ignore:
  - "tests/**"
  - "**/test_*.py"
  - "examples/**"
  - "docs/**"

# Rules to disable
disable_rules: []
  # - "SEC001"  # If using example API keys
  # - "PRI001"  # If false positives on prompt construction

# Secret detection tuning
entropy_threshold: 4.5  # Shannon entropy threshold
min_secret_length: 16

# AI-specific detection
detect_placeholder_secrets: true
detect_prompt_injection: true

# Performance
max_file_size_kb: 1024
parallel_workers: 4

🔌 CI/CD Integration

GitHub Actions

name: Security Scan

on: [push, pull_request]

jobs:
  security:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - uses: actions/setup-python@v5
        with:
          python-version: '3.11'
      
      - run: pip install ai-code-guard
      
      - name: Run security scan
        run: ai-code-guard scan . --format sarif -o results.sarif --fail-on high
      
      - name: Upload SARIF to GitHub Security
        uses: github/codeql-action/upload-sarif@v2
        if: always()
        with:
          sarif_file: results.sarif

Pre-commit Hook

# .pre-commit-config.yaml
repos:
  - repo: local
    hooks:
      - id: ai-code-guard
        name: AI Code Guard Security Scan
        entry: ai-code-guard check
        language: python
        types: [python]
        pass_filenames: false

GitLab CI

security-scan:
  image: python:3.11
  script:
    - pip install ai-code-guard
    - ai-code-guard scan . --format json -o gl-sast-report.json
  artifacts:
    reports:
      sast: gl-sast-report.json

📋 Rule Reference

Rule IDCategorySeverityDescription
SEC001-015SecretsCRITICAL/HIGHAPI keys (OpenAI, AWS, GitHub, Stripe, etc.)
SEC020-022SecretsCRITICALPrivate keys (RSA, SSH, PGP)
SEC030-031SecretsCRITICALDatabase credentials
SEC040SecretsMEDIUMJWT tokens
SEC050SecretsMEDIUMAI placeholder secrets
SEC099SecretsMEDIUMHigh-entropy strings
INJ001InjectionCRITICALSQL injection
INJ002InjectionCRITICALCommand injection
INJ003InjectionCRITICALCode execution (eval/exec)
DES001DeserializationCRITICALUnsafe YAML
DES002DeserializationCRITICALUnsafe pickle
SSRF001SSRFHIGHServer-side request forgery
PRI001-005Prompt InjectionHIGHDirect prompt injection
PRI006Prompt InjectionMEDIUMUser input in prompts
PRI010-011Prompt InjectionMEDIUMIndirect injection
DEP001DependenciesVARIESKnown suspicious packages
DEP002DependenciesHIGHTyposquatting detection
DEP003DependenciesHIGHDependency confusion

🔬 Technical Details

AST-Based Analysis

Unlike regex-based scanners, AI Code Guard Pro parses Python code into an Abstract Syntax Tree, enabling:

  • Taint tracking: Follow user input through variable assignments
  • Context awareness: Understand function calls and their arguments
  • Reduced false positives: Skip patterns in comments and strings

Entropy-Based Secret Detection

Uses Shannon entropy to distinguish real secrets from placeholders:

# High entropy (likely real secret) - DETECTED
api_key = "sk-proj-aB3xK9mL2pQrStUvWxYz..."

# Low entropy (placeholder) - IGNORED
api_key = "your-api-key-here"

LLM Security Focus

Specifically targets vulnerabilities in AI/LLM applications:

  • Detects prompt injection in OpenAI, Anthropic, and LangChain code
  • Identifies indirect injection risks in RAG pipelines
  • Flags unsafe patterns in agent/tool implementations

🤝 Contributing

Contributions welcome! See CONTRIBUTING.md for guidelines.

Adding Detection Patterns

# ai_code_guard_pro/analyzers/my_analyzer.py
from ai_code_guard_pro.models import Finding, Severity, Category

class MyAnalyzer:
    def analyze(self) -> list[Finding]:
        findings = []
        # Your detection logic
        return findings

📚 References

📄 License

MIT License - see LICENSE for details.


Built for the AI era by security engineers who use AI coding assistants daily 🛡️

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 13

Native requirements
13 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
click
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
click>=8.0.0runtime
gitignore-parser
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
gitignore-parser>=0.1.0runtime
pathspec
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
pathspec>=0.11.0runtime
pyyaml
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
pyyaml>=6.0runtime
rich
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
rich>=13.0.0runtime
tomli
Environment
{
  "extras": "",
  "marker": "python_version < \"3.11\"",
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
tomli>=2.0.0; python_version < "3.11"runtime
mypy
Environment
{
  "extras": "",
  "marker": "extra == \"dev\"",
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
mypy>=1.0.0; extra == "dev"runtime
pre-commit
Environment
{
  "extras": "",
  "marker": "extra == \"dev\"",
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
pre-commit>=3.0.0; extra == "dev"runtime
pytest-cov
Environment
{
  "extras": "",
  "marker": "extra == \"dev\"",
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
pytest-cov>=4.0.0; extra == "dev"runtime
pytest-xdist
Environment
{
  "extras": "",
  "marker": "extra == \"dev\"",
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
pytest-xdist>=3.0.0; extra == "dev"runtime
pytest
Environment
{
  "extras": "",
  "marker": "extra == \"dev\"",
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
pytest>=7.0.0; extra == "dev"runtime
ruff
Environment
{
  "extras": "",
  "marker": "extra == \"dev\"",
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
ruff>=0.1.0; extra == "dev"runtime
esprima
Environment
{
  "extras": "",
  "marker": "extra == \"js\"",
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
esprima>=4.0.0; extra == "js"runtime

Distribution files

2 collected
ai_code_guard-1.0.0-py3-none-any.whl

bdist_wheel · 34.15 KB · Python py3

Source file
ai_code_guard-1.0.0.tar.gz

sdist · 31.07 KB · Python source

Source file

Repository

PENDING
ai-code-guard/ai-code-guard

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 21 Oct, 10:13 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:7054c696072de89df766a0aea4736be151b71a883bb88e6abb1b4d0b7df5d204

Other collected versions

View all collected versions →