Architecture Note · Security & Compliance

Deterministic GHG Accounting & EU CSRD Audit Architecture

How a FastAPI and SQLite ledger enforces versioned Scope 1–3 calculations, ESRS E1–S1 gap tracking, and dual Sustainability and Controller sign-off locks for external limited assurance.

The Operational Problem: Unverifiable Spreadsheets Behind Statutory CSRD Audits

Sustainability teams, corporate controllers, and supply-chain ESG leads face a statutory tie-out problem under the EU Corporate Sustainability Reporting Directive (CSRD) and ISSB standards. Activity data arrives fragmented across global facilities—utility electricity invoices in kWh, fleet diesel logs, maritime freight tonne-kilometres, and accounts-payable procurement spend across hubs from Frankfurt and Zurich to Tokyo, Singapore, and Toronto. When emissions inventories live in ad-hoc spreadsheets, external limited-assurance auditors cannot trace a reported tCO2e figure back to its emission-factor version, contractual renewable certificate, and underlying proof document, while Scope 3 reporting remains distorted by generic spend-based estimates.

Why Naive AI Wrappers Fail in GHG & CSRD Assurance

Sending raw utility bills and supplier ledgers to a generic LLM prompt breaks financial-grade carbon accounting along four predictable fault lines:

  • Nondeterministic emissions math: Language models approximate unit conversions and blend outdated grid factors with supplier numbers, producing totals that cannot reproduce an exact activity_value × factor_value = tCO2e audit trail.
  • Conflated Scope 2 and Scope 3 baselines: Naive summaries collapse Scope 2 Market-based reporting (RECs, PPAs, and Guarantees of Origin) into Location-based grid averages, or leave Scope 3 Categories 1–15 locked to flat spend-based EEIO multipliers without separating data-refinement effects from physical abatement.
  • Unsupervised supplier outreach and data egress: Allowing an automated agent to email, SMS, or cold-call Tier-1 vendors over unapproved channels creates compliance risk, while retaining uploaded invoices in third-party cloud logs exposes sensitive procurement spend.
  • Uncontrolled period mutations: Without a cryptographic cutoff gate, late invoice corrections silently alter prior-quarter baselines after finance has prepared external assurance disclosures.

The Deterministic Architecture That Fixes It

A production ESG and CSRD ledger isolates deterministic accounting, versioned factor registries, and human sign-off gates inside a FastAPI and SQLite (WAL mode) backend:

  1. Versioned GHG Calculation Engine: POST /api/ghg/calculate and GET /api/ghg/factors operate behind tenant-scoped invite tokens (scripts/mint_invite.py) with sliding-window rate limits, ingesting JSON batches or temporary multipart CSV/JSON uploads in ESG_UPLOAD_DIR with automatic 1-hour (3600s) auto-wipe. Calculations execute against versioned emission_factors tables in SQLite (EPA eGRID, DEFRA, IEA, Ecoinvent, US EEIO, EXIOBASE, PCAF), computing Scope 1 combustion, dual Scope 2 Location-based and Market-based tCO2e, and Scope 3 Categories 1–15 with supplier_specific primary EPD overrides.
  2. ESRS E1–S1 Double Materiality & Gated Outreach: POST /api/csrd/assess scores quantitative datapoint coverage across ESRS E1–E5 and S1 against esrs_datapoint_rules thresholds and defaults to OfflineDeterministicAdapter with zero external API keys required. Missing supplier datapoints generate structured primary-data requests restricted to verified Supplier Portal links or opt-in Official WhatsApp Business Cloud API workflows after explicit ESG-lead attestation.
  3. EEIO vs. Supplier EPD Abatement Modeling: Across Logistics (4,180 tCO2e EEIO vs. 3,120 tCO2e supplier EPD), Cloud Infra (2,480 vs. 1,390 tCO2e), and Tier-1 Manufacturing (7,640 vs. 5,490 tCO2e), the comparator separates primary-data refinement from physical renewable PPA and clean-fleet abatement against internal carbon shadow pricing.
  4. Dual Human Assurance Lock & Provenance Export: POST /api/reports/{period}/assure enforces HTTP 409 Conflict unless both sustainability_lead_approved=true and finance_controller_approved=true plus confirm_assurance_lock=true are submitted. Once locked, new calculations against that period fail closed with HTTP 409, an inventory_sha256 is recorded in period_assurances and SHA-256 hash-chained audit_logs, and GET /api/ghg/audit-trail (or audit-trail.csv) exports full provenance with OWASP RFC 4180 formula-injection sanitization and pytest-verified math.

Operational Takeaway

External CSRD assurance requires reproducible arithmetic, not fluent summaries. When emission factors are version-locked in SQLite, Scope 2 dual reporting and Scope 3 EPD overrides preserve full formula provenance, supplier campaigns require human approval, and period cutoffs lock behind Sustainability and Finance Controller sign-off, teams cut audit tie-out friction without risking unverified numbers.

Test an audit-ready ESG ledger on your own emissions data

Start with a free 30-minute workflow check. Bring utility invoices, freight tonne-km logs, or procurement spend extracts and leave with one concrete recommendation in writing within one business day.