Skip to main content

CLI guardrail for catching stale Python APIs before runtime.

Project description

llm-code-validator

Python CLI for detecting stale or version-incompatible third-party API usage in Python source code.

Installation

Install from the repository:

git clone https://github.com/mathew-felix/llm-code-validator
cd llm-code-validator
pip install -e .

Install with test dependencies:

pip install -e ".[dev]"

After the package is published to PyPI:

pip install llm-code-validator

Usage

Check one file:

llm-code-validator check file.py

Check a directory:

llm-code-validator check src/

Check standard input:

llm-code-validator check - < snippet.py

Check staged Git files:

llm-code-validator check --staged

Use an explicit dependency file:

llm-code-validator check --requirements requirements.txt src/

Show low-confidence diagnostics:

llm-code-validator check --show-low-confidence src/

Exit codes:

  • 0: no diagnostics
  • 1: diagnostics found
  • 2: tool error

Output

Text output:

llm-code-validator check src/

JSON output:

llm-code-validator check src/ --format json

GitHub Actions annotation output:

llm-code-validator check src/ --format github

Fixes

Preview fixes:

llm-code-validator fix file.py

Apply safe fixes:

llm-code-validator fix file.py --write

Only rules marked safe_fix are written. Rules marked suggested_fix or no_fix are reported but not changed.

Current rule safety counts:

  • safe_fix: 15 rules
  • suggested_fix: 51 rules
  • no_fix: 2 rules

Signature Database

Validate the rule database:

llm-code-validator validate-signatures

The source rule database is:

data/library_signatures.json

The packaged rule database is:

llm_code_validator/library_signatures.json

Current rule count:

  • 68 API-drift rules

Benchmarks

Run the CLI benchmark dataset:

python -m llm_code_validator.benchmark --dataset validation_dataset/cli_benchmark_cases.json

Run the AI-stack benchmark dataset:

python -m llm_code_validator.benchmark --dataset validation_dataset/ai_stack_benchmark_cases.json

Current saved benchmark results:

  • CLI dataset: precision 1.0, recall 1.0, p50 0.243ms, p95 6.199ms
  • AI-stack dataset: precision 1.0, recall 1.0, p50 0.444ms, p95 4.939ms

Pre-Commit

.pre-commit-hooks.yaml is included:

repos:
  - repo: https://github.com/mathew-felix/llm-code-validator
    rev: v0.1.0
    hooks:
      - id: llm-code-validator

GitHub Actions

Example workflow:

name: API Drift Check

on:
  pull_request:

jobs:
  api-drift:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.11"
      - run: pip install llm-code-validator
      - run: llm-code-validator check . --format github

Testing

Run the test suite:

pytest -q

Current local result:

72 passed

Documentation

  • docs/demo.md: example check and fix workflow
  • docs/rules.md: rule database notes
  • docs/release.md: package release steps
  • PROJECT_REPORT.md: project report

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_code_validator-0.1.0.tar.gz (28.8 kB view details)

Uploaded Source

Built Distribution

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

llm_code_validator-0.1.0-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for llm_code_validator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a4e905bbb9746080038e7a91f4fd83fc866c36d0a943d777451cc8fa4cf8591b
MD5 ec2b2e1687048825f702bc2b97d284cb
BLAKE2b-256 8bc3f22fd93fe7f2df8fef93c3296809ae352daf9104ea690db9d7d4233c2d5b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llm_code_validator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d541066a85b9a0df8d0c9d341a40e204885d6102a5d2942b31e5cae7e09775eb
MD5 4f0164217fc0092869e1a612d66a5a08
BLAKE2b-256 46f7cbf00d55c7dd3a92720328968ef73638ace8650ffe5477afd628e38efac9

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