AI-COMPETE use case · system design

Climate Figures an Auditor Can Trace Back to the Meter

Large manufacturers, like the groups behind the AI-COMPETE and SMART partners, now report energy use and greenhouse-gas emissions under the EU’s Corporate Sustainability Reporting Directive (CSRD), and those figures are audited. This multi-agent system prepares the climate datapoints of the ESRS E1 standard: energy consumption and mix, and Scope 1 and 2 emissions. Each one is a validated, structured record that carries its calculation, source data, emission-factor version, regulation clause and reviewer sign-off. The language models parse, ground and explain. Code does the arithmetic.

ContextUniversity of Skövde · AI-COMPETE (Vinnova) · 2026 · system design
Analytics stages
QualitativeDescriptiveDiagnosticPredictivePrescriptiveSoftware
Technology
LangGraph (Postgres checkpointer)Pydantic v2InstructorAzure OpenAI (structured outputs)PostgreSQLFastAPIReact review UIDockerAzure (Sweden Central)OpenTelemetry
ResultSystem design — agent workflow, validation rules, human sign-off and audit trail. No reporting results are claimed yet.
What this page is. A system design for a compliance use case from the AI-COMPETE programme. It is not a report of a deployment at any partner, and it is not legal or assurance advice. Figures marked target are release gates. They are not measured results.
Stakeholder engagement · problem formulation

Every number is audited, and the rules keep moving

Where a plausible answer is useless, because an auditor will ask how it was made.

A climate datapoint such as “Scope 2 emissions, market-based, for the reporting year” looks like one number. Producing it means pulling metered electricity for every site and month, matching each supply contract and guarantee of origin, choosing the right emission factors, applying the GHG Protocol method that ESRS E1 refers to, and explaining any gap. Today that is spreadsheets passed between sites. At audit time nobody can say which version of which factor produced which cell.

The requirements came from the sustainability controllers who sign the figures:

Architecture · multi-agent workflow

Five roles, one state machine, and one person with the final say

LangGraph orchestrates the agents. Its state is saved to PostgreSQL after every step, so a workflow can wait days for a reviewer.
Parse, ground, calculate, validate, sign, all of it logged Request parserdatapoint, period,sites in scope Grounding agentESRS clause + method,versioned, cited Calculation engineplain code, no LLM:activity × factor ValidatorPydantic schema +business rules Reviewerapprove, editor reject Datapointto reporting DB+ evidence pack rule broken → engine re-runs or flags the gap rejected with a reason → back into the workflow, state preserved Compliance audit log — append-only, hash-chained every input, prompt, model version, tool result, validation verdict, edit and approval Tool failures take a deterministic fallback path: retry with backoff, then flag the gap as data missing. The engine never guesses a default value.
Language models sit at the edges, parsing requests and grounding rules. The number itself is produced by code that an auditor can read.
  1. Request parser. Turns “prepare E1-6 Scope 2 for 2025, all Swedish sites” into a typed request: datapoint ID, reporting period, organisational boundary and sites. Instructor with a Pydantic model makes the output a valid object or an explicit error, never loose text.
  2. Knowledge-grounding agent. Retrieves the ESRS E1 paragraphs and the GHG Protocol method for the datapoint from a versioned rule library, and returns the method as a structured specification with citations, tagged with the rule version it relies on.
  3. Calculation engine. Plain, tested Python, not a model. It pulls activity data (metered energy, fuel purchases, supply contracts) through read-only queries. It applies emission factors from a versioned factor table, computing both location-based and market-based Scope 2, and returns the figure with a line-by-line calculation trace.
  4. Validator. Pydantic v2 models enforce the schema, units and allowed values. Business rules then check that all sites are covered for all months, that totals match their parts, that the energy mix adds up, and that large year-on-year jumps carry an explanation before review.
  5. Reviewer and audit logger. A sustainability controller sees the figure, the trace, the sources and the cited rule, then approves, edits with a reason, or rejects. Every step, before and after, is written to the audit log.
Engineering · guarantees

What the system promises, and how each promise is kept

Each guarantee has a mechanism in code, not a sentence in a prompt.
GuaranteeMechanism
Always schema-validProvider structured outputs constrain the model to the JSON schema. Instructor re-asks with the validation error if a field fails a Pydantic rule. After a set number of tries the step fails loudly instead of passing a near-miss downstream.
Reproducible figuresCalculations in versioned code, with exact decimal arithmetic. The inputs, factor-table version and code version are stored with each result, so a re-run gives an identical number.
No silent defaultsA missing meter, contract or factor becomes an explicit gap. Estimation is allowed only by a named, disclosed method, and it is flagged on the datapoint.
Graceful tool failureIdempotent tool calls with retries and backoff, a circuit breaker on each data source, and a dead-letter queue for steps a person must resolve. The workflow pauses; it does not improvise.
Persistent stateLangGraph checkpoints in PostgreSQL after every node. A workflow waiting on a reviewer survives restarts and deploys, and resumes exactly where it stopped.
Tamper-evident logAppend-only audit table in which each entry carries the hash of the previous one. The chain is verified nightly, and any gap or edit breaks it visibly.
Security & compliance

Built to be questioned by an auditor and attacked by a document

The threats are a wrong number that looks right, and text that tries to give orders.

Controls

  • Role-based access: preparers, reviewers and auditors get different views and different actions. Four-eyes approval is required for material datapoints.
  • Read-only credentials to source systems, scoped to one workflow run and short-lived.
  • All data, models and logs in Azure’s Sweden Central region, with encryption at rest and customer-managed keys.

Threats handled

  • Prompt injection from supplier invoices and contracts: document text is passed to the model as quoted data, and a document can never trigger a tool call.
  • Hallucinated citations: every cited ESRS paragraph ID is checked against the rule library before the output is accepted.
  • Rule drift: when the rule library gets a new version, the datapoints that cite a changed paragraph are flagged for re-review.
Evaluation

Back-tested against a year that was already reported and audited

The best test set is last year’s signed-off figures.

The system recomputes a previously reported year from the raw source data. Its figures and evidence are compared with the audited report, and every difference is explained or traced to a data or method correction.

MetricHow it is measuredRelease gate (target)
Schema validityOutputs that validate against the Pydantic models, at every stage100% (hard gate)
ReproducibilityRe-runs from stored inputs that give an identical figure100% (hard gate)
Citation validityCited rule paragraphs that exist in the library version used100%
Back-test agreementDatapoints within tolerance of the audited figure, or with a documented reason100% explained
Reviewer reworkDatapoints a reviewer had to edit or rejecttracked, falling per cycle
Audit-chain integrityNightly hash-chain verification0 breaks
Production

From a workflow engine to a tool controllers use at year-end

Containerised, observable, and hosted on the shared platform.
Review UIReact: a queue of datapoints awaiting review, each with its figure, calculation trace, source records, cited rule and history, plus one-click export of the evidence pack for the auditor.
ServicesFastAPI running the LangGraph workflows in Docker on Azure Container Apps, with PostgreSQL for checkpoints, results and the audit chain, and OpenTelemetry tracing each node.
PlatformHosted as a workspace on the multi-tenant GenAI platform. Activity data comes through the data analyst agent’s validated, read-only query layer.