Skip to main content

Premium VBA static analyser & compile-safety prechecker for AI-generated VBA

Project description

VBAlidator

Premium VBA static analyser & compile-safety prechecker for AI-generated VBA. Drop-in behind any LLM-VBA generator — get a deterministic 0–100 confidence score and a stable JSON report before the code ever reaches a workbook.

PyPI version CI Docker Docs License: MIT

VBAlidator parses .bas / .cls / .frm files through a real lexer / preprocessor / parser / analyzer pipeline, applies 41 documented rules (see the catalogue), and returns a verdict CI pipelines and AI agents can act on directly.

What it catches

The full list lives at docs/rules/index.md. The high-impact subset that AI generators trip over most often:

  • VBA001 undefined identifiers, VBA002 missing object members
  • VBA006 wrong argument count, VBA007 ByRef type mismatches
  • VBA210 Set on scalar, VBA211 missing Set on object assignment
  • VBA221–VBA224 Property Get/Let/Set arity & semantics
  • VBA230 / VBA231 non-constant Const initialisers
  • VBA240 arithmetic between string and numeric literal
  • VBA300 missing PtrSafe on 64-bit Office Declares
  • VBA320 missing Option Explicit (warning)
  • VBA330 incomplete Implements of an interface
  • VBA340 / VBA341 RaiseEvent without matching Event declaration / wrong arity
  • VBA_LEX001 / VBA_LEX002 unrecognised characters & malformed date literals
  • VBA_RT001 (optional) errors caught by the actual VBE compiler via Office round-trip

Install

pip install vbalidator

…or grab the multi-arch image:

docker pull ghcr.io/twobeass/vbalidator:latest

In one CLI call

vbalidator ./MyModules --host excel
MyModules/Module1.bas:42: ERROR  [VBA001]  Undefined identifier 'tpyo' in 'DoStuff'.
MyModules/Module1.bas:1:  WARNING [VBA320]  Module 'Module1' is missing `Option Explicit`.

Files scanned : 12
Errors        : 1
Warnings      : 1
Confidence    : 77 / 100  (needs fixes)
Report saved  : vba_report.json

Exit code is 1 when the score is below the gate (--score-threshold, default 90) or there is at least one error.

In one Python call

from vbalidator import precheck

result = precheck("Module1.bas", host="excel")

if result.compile_safe:
    deploy(result)
else:
    for err in result.errors:
        print(f"{err['rule_id']}: {err['message']}")

print(f"score = {result.score} / 100")
print(result.json())   # canonical JSON v2 report

PrecheckResult exposes errors, warnings, info, issues, and the canonical .json() report. It's also truthy when compile_safe, so if precheck(...): ... is idiomatic.

See docs/ai-integration.md for full recipes (Anthropic SDK, OpenAI Agents, LangChain, GitHub Actions).

Optional dynamic verification

When a Windows host with Office is available, cross-check the static verdict against the actual VBE compiler:

vbalidator ./MyModules --host excel --roundtrip
result = precheck("Module1.bas", host="excel", roundtrip=True)

Compile errors VBE itself reports come back with severity='compile_verified' and rule_id VBA_RT001. On non-Windows hosts the call degrades gracefully to a single info-level notice instead of crashing.

Bundled host models & auto-layering

--host excel|word|access|outlook|visio auto-loads the matching Office host model from src/models/. Excel/Word/Access/Visio are full-fidelity exports of the real Office type libraries (1–3 MB each, ~1000 classes apiece, ~5000 globals/classes in Excel alone); Outlook is a hand-curated stub (the Trust-Center AccessVBOM path is GPO-blocked on managed installs).

In addition, six companion stubs auto-layer without an explicit --host flag whenever any scanned file mentions their ProgID / namespace:

Stub Triggers on Top classes
mscomctl .frm referencing ComctlLib TreeView, ListView, Toolbar, ProgressBar
msforms source mentioning MSForms. UserForm, CommandButton, TextBox, Frame
scripting Scripting.Dictionary / Scripting.FileSystemObject Dictionary, FSO, Drive, Folder, File, TextStream
vbscript_regexp VBScript.RegExp RegExp, Match, MatchCollection, SubMatches
wscript_shell WScript.Shell Shell, WshExec, WshEnvironment
shell_application Shell.Application Shell.Application, Shell.Folder, Shell.FolderItem

So --host excel covers the vast majority of real-world spreadsheet VBA — TreeView/UserForm/Dictionary/RegExp code resolves automatically. Run vbalidator --help for the full --host choice list.

Documentation

The full site is at https://twobeass.github.io/VBAlidator/ — deployed automatically from main by .github/workflows/docs.yml.

In-repo:

  • Quickstart — install → scan → ship
  • GitHub Actions integration — copy-paste workflow recipes (path-filter, JSON artifact, PR annotations, multi-host matrix, step summary, status badge)
  • AI pipeline integration — patterns for Claude, OpenAI Agents, LangChain
  • Usage — full CLI / Python API reference
  • Configuration — host models, custom models, conditional-compilation defaults, heuristics
  • Architecture — pipeline internals
  • Rule catalogue — all 41 rules with examples
  • CI / CD — workflows, release lifecycle, branch protection
  • UAT walkthrough — section-by-section human validation script for the current branch
  • TODO — open items that need a Windows machine, live PyPI/GHCR/Pages access, or future code work
  • Roadmap — what's done, what's queued

Development

git clone https://github.com/twobeass/VBAlidator
cd VBAlidator
pip install -e ".[dev]"
pytest                              # 259 tests
ruff check src tests                # lint
python tools/generate_rule_docs.py  # refresh docs/rules/ after a rule change

PR titles must follow Conventional Commits (feat: / fix: / docs: …). The release pipeline derives the next semver bump from your commit history.

License

MIT.

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

vbalidator-1.7.0.tar.gz (579.3 kB view details)

Uploaded Source

Built Distribution

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

vbalidator-1.7.0-py3-none-any.whl (567.5 kB view details)

Uploaded Python 3

File details

Details for the file vbalidator-1.7.0.tar.gz.

File metadata

  • Download URL: vbalidator-1.7.0.tar.gz
  • Upload date:
  • Size: 579.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for vbalidator-1.7.0.tar.gz
Algorithm Hash digest
SHA256 5f48cba8f322aa40a9bc08069043405d2417ce89d663dfe9f0104f8a153fc990
MD5 b08154274ac384c9f36381091dd195f8
BLAKE2b-256 2af2c493495bacfda2cf11cb23f489ed85c9c4c35d650ce9d362abf5f9d58e5d

See more details on using hashes here.

Provenance

The following attestation bundles were made for vbalidator-1.7.0.tar.gz:

Publisher: release.yml on twobeass/VBAlidator

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

File details

Details for the file vbalidator-1.7.0-py3-none-any.whl.

File metadata

  • Download URL: vbalidator-1.7.0-py3-none-any.whl
  • Upload date:
  • Size: 567.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for vbalidator-1.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7e0908aa2ecf20f9ceac9e13b89993a9ba5271dd4fc760bd8cfbbbd047fd5754
MD5 9eee132148c4309485e452c479377ad5
BLAKE2b-256 996eb29ff56d85fd9402fc2541cab13a07d1e657608c17aed1b44ed862f35d24

See more details on using hashes here.

Provenance

The following attestation bundles were made for vbalidator-1.7.0-py3-none-any.whl:

Publisher: release.yml on twobeass/VBAlidator

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