Skip to content
← Writing

Public sector · 11 min · 4 May 2026

Encoding CWMF as code.

A walk through how we translated the Capital Works Management Framework into a deterministic, rules-based routing engine — the data model, the rule shape, the audit log. Predicates, not predictions. The framework procurement officers already follow, applied consistently in software.

AuthorLiam, FounderNexum · Dublin

1 · Why frameworks resist code

The Capital Works Management Framework — CWMF — is the framework Irish public bodies use to deliver capital projects. It is well written. It is detailed. It is unusually consistent for a government framework. And it is, today, mostly enforced by Outlook, SharePoint, and the institutional memory of one or two senior people in every project office.

That last bit is the problem. CWMF describes a sequence of decisions — a project moves from initiation, through approval gateways, to delivery — and at each gate the rules about who decides, against what evidence, and to what threshold are non-trivial. If those rules live in PDFs and habits, they are applied unevenly. If they live in code, they aren’t.

The translation isn’t obvious, though. Frameworks are written for humans. They use ranges, guidance, “normally,” “where appropriate.” Code wants predicates, not adverbs. Most of the work in encoding a framework is figuring out which adverbs are real flexibility and which are just shorthand for an unstated rule.

2 · Three layers of translation

We split the work into three layers. Each one has a different shape and a different test.

  • Rules. Predicates, sourced to a citation. Pure functions of a decision’s context.
  • Decisions. Events that record an actor, an intent, and the rule outcome. Append-only, never edited.
  • Evidence. Documents and justifications attached to a decision at the moment it’s made. Sealed and hashed when the decision closes.

Splitting along these lines matters because the audit answer for each is different. “Did the right rule fire?” is a unit-testable question. “Did the right person sign?” is an identity question. “Was the evidence present?” is a content question. Three problems, three solutions, three kinds of test.

3 · A worked example: an approval gateway

Take a single CWMF moment: a project moving from preliminary business case to detailed business case approval. The framework says the decision routes to different approving authorities depending on the project’s estimated outturn cost band, with additional sanctions for projects above certain thresholds. There is a standard form, there is a sequence, there is an audit expectation.

Encoded, the rule looks roughly like this:

// rules/cwmf/approval-routing.ts
export const approvalRouting = defineRule({
  id: "cwmf.approval-routing.v1",
  title: "CWMF approval gateway routing",
  source: {
    framework: "CWMF",
    citation:  "CWMF v1.4 §2.3",
    url:       "https://constructionprocurement.gov.ie/...",
  },
  inputs: z.object({
    estimatedOutturnEUR: z.number(),
    sponsoringAgency:    z.string(),
    riskCategory:        z.enum(["low", "medium", "high"]),
  }),
  evaluate(ctx) {
    if (ctx.estimatedOutturnEUR < 200_000) {
      return { route: "local", approver: "sponsoring-agency-head" };
    }
    if (ctx.estimatedOutturnEUR < 20_000_000) {
      return { route: "agency-board", approver: "agency-board" };
    }
    return { route: "sanctioning-authority", approver: "deah" };
  },
});

The shape matters more than the specifics. A rule has an id, a source that points at a citation, an input schema (we use Zod; ArkType works equally), and a pure evaluate function. The routing decision is data, not text.

The version suffix on the id (.v1) is load-bearing. When CWMF revises — and it does — we ship cwmf.approval-routing.v2 alongside, leave v1 in place for projects that started under it, and route by the project’s declared framework version. Audit reviewers four years from now can replay the rule that fired without archaeology.

4 · Sourcing every rule to its citation

The single most useful discipline we’ve adopted: every rule carries the URL or document section it came from, in the data, not in a comment. When a reviewer asks “why did this approval go to the board and not to the Department?”, the answer is two clicks deep —decision.routedBy.source.url.

That citation field is the difference between a system that can be audited and one that is built to be audited. The cost is small (one extra struct, one URL per rule). The payoff is large: the framework reference becomes a living link, not an institutional memory.

5 · The model at the edges, never at the centre

A note for the procurement professionals reading this: the decision in this system is yours, not a model’s. The engine above is deterministic — pure functions of inputs you can see, sourced to citations you can read. Same input, same output, every time.

People sometimes expect “AI for procurement” to mean a chatbot that decides things. It doesn’t — at least not in anything we’d be willing to put our name on. The model does three useful jobs around the deterministic core, and only three:

  • Extraction. Reading a brief, a tender, a project memo, and proposing structured fields the human will confirm. Tool-using, JSON-schema-output, evaluated against a growing test set.
  • Classification. Mapping free-text descriptions to CWMF categories or risk bands. Always shown to the user with confidence and source spans, never silently applied.
  • Drafting. Producing the first draft of a standard form (PWF series) from already-captured fields, for the human to revise.

None of these is a decision. Each is an artefact attached to a decision the human still makes. When the model is wrong, the audit log shows the human’s correction, the model’s original output, and which eval set caught the regression in CI. The model is accountable to the system it lives in.

6 · Output: events, packs, audit

The decision itself is recorded as an event. Roughly:

// events/decision-routed.ts
type DecisionRouted = {
  type: "decision.routed",
  decisionId: string,
  projectId: string,
  ruleId: string,            // e.g. "cwmf.approval-routing.v1"
  ruleSource: { framework, citation, url },
  inputs:  Record<string, unknown>,
  output:  { route, approver },
  actor:   { id, role, identityProvider },
  at:      ISODateTime,
  hash:    string,           // content hash; chained to prior
};

The event is append-only. There is no decision.update verb in our schema, ever. Corrections are decision.superseded events that point at the prior event by hash. The audit log isn’t a side effect of the system — it is the system. The UI is a projection over it; the document pack is a render of it; the “state” of a decision is a fold of its events.

When a decision closes, we seal a pack: the inputs, the rule output, the evidence documents, the actor identities, all hashed and signed at the moment of closing. We can rebuild any past pack from the event log alone. We can detect any drift between the rendered pack and the events because the seal hash won’t verify.

7 · What we shipped, and what we left out

The first version of GovIQ ships with this backbone and a small number of CWMF rules — approval routing, evidence presence checks, threshold flagging, a handful of stage-gate preconditions. We deliberately ship narrow. The rules we haven’t encoded yet are not implied to be enforced. Pretending otherwise is the failure mode that gets vendors quietly removed from procurement frameworks.

If you’re a public body looking at this and thinking “that’s the project I want to do for ours,” we’d like to hear about it. The pattern generalises: you can apply it to OGP guidance, to BCAR sign-offs, to HIQA self-assessment, to any framework that’s currently enforced by spreadsheet and habit.

The studio works on this kind of system end to end — design, build, operate, hand over.

If this matches your work

Talk to us about a one-week discovery on your framework.

Fixed fee. We produce a written architecture memo for your framework — rule shape, citations, decision schema, audit log design — whether or not we go on to build it.