Multi-Currency Ledger & Financial Invariant Auditor

    by Víctor Betancourt

    1

    Static Python/SQLAlchemy financial AST scanner and multi-currency split-tender ledger auditor.

    $15

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI Agents you already use

    Multi-Currency Ledger & Financial Invariant Auditor

    Example session with this skill installed

    Scan the ./backend/orders directory for financial float leaks and insecure Decimal usage, then provide a fix for any detected PG-001 or FIN-002 errors.

    • Read your context and instructions
    • Compiled the multi-currency ledger

    I have completed the static AST scan of the ./backend/orders directory. The audit identified two critical financial invariants violations: a Float column definition in the SQLAlchemy model and an unsafe Decimal constructor using a float literal.

    Financial Audit Results

    Rule IDSeverityFileLineFinding
    PG-001Highmodels.py42Column(Float) used for unit_price
    FIN-002Highservices/calc.py89Decimal(19.99) detected (binary float drift)
    SEC-001Mediumschemas.py115gross_margin found in ProductPublicOut

    Recommended Fixes

    
    # models.py - Replace Float with Numeric
    from sqlalchemy import Numeric
    
    # Change: unit_price = Column(Float)
    unit_price = Column(Numeric(18, 4), nullable=False)
    
    # services/calc.py - Replace float literals with strings
    from decimal import Decimal
    
    # Change: tax = Decimal(19.99)
    tax = Decimal("19.99")
    
    # schemas.py - Isolate margin from public DTOs
    class ProductPublicOut(BaseModel):
        id: int
        name: str
        price: Decimal
        # Remove: gross_margin: Decimal
    

    Next steps

    1. Run python3 scripts/scan_ledger_code.py ./backend/orders --json to verify the fixes.
    2. Apply the NUMERIC(18, 4) migration to your PostgreSQL database using the provided DDL templates.
    3. Review references/financial-concurrency-invariants.md to ensure ORDER BY sku ASC is added to all checkout queries.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Financial systems fail silently when binary floats cause rounding drift or race conditions lead to deadlocks. This skill audits Python and SQLAlchemy backends to enforce strict monetary invariants and deterministic concurrency patterns in multi-currency ledgers.

    What it does

    • AST Code Scanning identifies high-risk float usage, unsafe Decimal(float) constructors, and incorrect SQLAlchemy column types for monetary data.
    • Multi-currency Settlement Auditing validates JSON invoice exports to ensure conservation of value across USD, EUR, and crypto tenders while blocking split-rounding pumping.
    • Concurrency Enforcement detects multi-row FOR UPDATE locks missing deterministic ORDER BY clauses to prevent PostgreSQL and SQLite deadlocks.
    • Schema Boundary Checks flags internal cost, margin, and wholesale fields accidentally exposed in public or seller Pydantic/response DTOs.
    • Transaction Logic Validation ensures duplicate SKUs are aggregated before stock checks to prevent inventory bypass exploits.

    How it works

    1. Static Analysis runs the scan_ledger_code.py tool on your Python repository to detect FIN-001 through ERR-001 violations.
    2. Settlement Review uses audit_settlement.py to process multi-currency invoice fixtures and verify rounding logic and FX conversions.
    3. DDL Implementation applies provided PostgreSQL or SQLite schema templates that use NUMERIC types and identity columns.
    4. Concurrency Hardening implements the global lock hierarchy (invoice -> payments -> products sorted by SKU) using the provided SQL references.

    Frameworks & tools

    This skill is built for Python 3.10+ environments using SQLAlchemy, PostgreSQL, and SQLite WAL. It integrates with Pydantic for DTO validation and uses standard library AST parsing for zero-dependency static analysis.

    Why this beats prompting it yourself

    Prompting alone often misses subtle IEEE-754 precision errors or complex row-level locking orders that lead to race conditions. This skill provides a specialized AST scanner and deterministic audit scripts that catch financial edge cases a general LLM might overlook during a standard code review.

    Use cases

    • Audit a multi-currency checkout pipeline for precision loss and FX rounding errors.
    • Scan a legacy SQLAlchemy codebase to migrate unsafe Float columns to Numeric.
    • Harden a POS backend against deadlock errors under high concurrent load.
    • Validate that internal margin data is isolated from public catalog API responses.

    Known limitations

    The scanner requires Python 3.10 or higher. It only analyzes static code patterns and cannot detect runtime logic errors that occur outside the audited AST or JSON structures.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed 8 days ago

    Software
    Python 3.10+

    Permissions

    Terminal / Shell
    Read Files
    Listed8 days ago

    What's inside

    Frequently Asked Questions

    This skill prevents 'silent' financial failures, such as rounding drift caused by float-based arithmetic and database deadlocks resulting from non-deterministic row locking in high-concurrency environments.

    The skill is designed for Python 3.10+ environments using SQLAlchemy, with optimized schema templates for PostgreSQL and SQLite (WAL mode). While it focuses on these stacks, the AST scanning logic can be adapted for any Python-based backend.

    You receive the specialized AST scanner (`scan_ledger_code.py`), the settlement auditor (`audit_settlement.py`), a library of SQLAlchemy/DDL schema templates, and the global lock hierarchy reference for concurrency hardening.

    While a general LLM might overlook subtle IEEE-754 precision errors, this skill uses static analysis to catch specific violations (FIN-001 through ERR-001) that are often missed during standard manual code reviews.

    The skill includes a 'Schema Boundary' check that flags when sensitive internal fields—like wholesale costs or profit margins—are accidentally exposed via public Pydantic models or DTOs.

    The scanner is a static tool that integrates into your CI/CD pipeline or local development environment; simply point it at your repository to generate a report on monetary invariants and concurrency risks.

    New in Finance & Accounting

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Finance & Accounting.