Skip to main content

LogicGuard

CI PyPI License: MIT

LogicGuard is an open-source, diff-aware static + LLM reasoning engine that catches business-logic flaws and AI-generated code bugs that regex linters miss.

Website · Contributing

Quickstart

Run LogicGuard directly with uvx or install it globally with pipx:

# Run without installing (zero-network AST pre-filter mode)
uvx logicguard diff --offline-only

# Or install globally with pipx
pipx install logicguard
logicguard scan src/

Scan a git diff using local Ollama (qwen2.5-coder:7b by default) or a cloud provider:

# Local Ollama (100% offline, default provider)
uvx logicguard diff --base main

# OpenRouter (e.g. free or custom models)
OPENROUTER_API_KEY=... uvx logicguard diff --provider openrouter --model openrouter/free

# Anthropic Claude
ANTHROPIC_API_KEY=... uvx logicguard scan src/ --provider anthropic

GitHub Action

Drop LogicGuard into any pull request workflow to scan changed functions and upload SARIF 2.1.0 alerts directly to GitHub Code Scanning:

name: LogicGuard Security Scan

on:
  pull_request:

permissions:
  contents: read
  security-events: write

jobs:
  logicguard:
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Run LogicGuard diff scan
        uses: Aviation3006/logicguard@v0.1.0
        with:
          provider: openrouter
          model: openrouter/free
          api-key: ${{ secrets.OPENROUTER_API_KEY }}
          fail-on: high

Set offline-only: "true" if you want deterministic AST-only scanning with no API key, or pass provider: anthropic with your ANTHROPIC_API_KEY.

Built-in Rules

LogicGuard ships with five AST + LLM rules supporting Python, JavaScript, TypeScript, and TSX (logicguard rules):

Rule ID Title Default Severity CWE Languages
auth_bypass Missing or Removed Authentication/Authorization Guard CRITICAL CWE-862 Python, JS, TS, TSX
ai_hallucinated_guard Hallucinated, Inverted, or No-Op Security Guard HIGH CWE-863 Python, JS, TS, TSX
idor_ownership Insecure Direct Object Reference (Missing Ownership/Tenant Check) HIGH CWE-639 Python, JS, TS, TSX
race_toctou Time-of-Check to Time-of-Use (TOCTOU) Race Condition HIGH CWE-367 Python, JS, TS, TSX
silent_except Silent Exception Swallowing Around State Changes HIGH CWE-390 Python, JS, TS, TSX

Example CLI Finding

+---------------------------------- app/routes/admin.py:1-6 -----------------------------------+
| [CRITICAL] auth_bypass - Missing or Removed Authentication/Authorization Guard               |
| Location: app/routes/admin.py:1-6 | Confidence: 0.96 | CWE-862                               |
| > 1 @app.post("/api/admin/users/{user_id}/promote")                                          |
| > 2 def promote_user(user_id: int, db: Session = Depends(get_db)):                           |
| > 3     user = db.get(User, user_id)                                                         |
| > 4     user.role = "admin"                                                                  |
| > 5     db.commit()                                                                          |
| > 6     return {"status": "promoted"}                                                        |
| Explanation: State-mutating admin endpoint promotes a user role without any authentication   |
| or admin role check dependency.                                                              |
| Remediation: Require an authenticated admin user via Depends(require_admin) and verify       |
| permissions before updating user.role.                                                       |
+----------------------------------------------------------------------------------------------+
                   Scan Summary                   
+------------------------------------------------+
| Findings             | 1                       |
| Files scanned        | 3                       |
| Candidates evaluated | 2                       |
| Provider             | ollama:qwen2.5-coder:7b |
| Duration             | 412.8 ms                |
+------------------------------------------------+

Adding a new security rule takes just two files (src/logicguard/rules/<rule_id>.py and tests/rules/test_<rule_id>.py) with automatic discovery and zero central registry edits — see CONTRIBUTING.md.

Metadata

Release files for logicguard 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for logicguard 0.1.0
File Size Uploaded Provenance Actions
logicguard-0.1.0.tar.gz 251.9 kB With provenance Details for logicguard-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for logicguard 0.1.0
File Interpreter ABI Platform Actions
logicguard-0.1.0-py3-none-any.whl Python 3 none any Details for logicguard-0.1.0-py3-none-any.whl

Total release size: 316.2 kB

Release files / logicguard-0.1.0.tar.gz

Download URL logicguard-0.1.0.tar.gz
Size 251.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8eda1377209b6222ff2bf0ff757b004bfccf188d00cb97d2ba3f4a54a1bbddfb
BLAKE2b-256 checksum
How to use checksums
deb6b6896ec220bc521eda40016a5b1ec534fc26507d8cb705ca86ab5851fc53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.

Transparency log

Release files / logicguard-0.1.0-py3-none-any.whl

Download URL logicguard-0.1.0-py3-none-any.whl
Size 64.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e986915d7b0b575ba0f3969855e784caa6cc4446b7ae42e45a834f2334eb0f11
BLAKE2b-256 checksum
How to use checksums
44b31c61332f8577b1611e487c8ec51688e9aa624f0d8ece82ef9d340894b165
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.

Transparency log

Security for logicguard 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for logicguard-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page