What Is Rules as Code, With a Runnable Example

Rules as Code publishes a rule in a form a machine can execute, next to the text a person reads. Here is the definition, where the idea comes from, and a limitation period you can compute yourself.

A lawyer in a gown feeds an enormous codex into a small hand-cranked calculating machine while a chess arbiter with a blue armband waits in line holding a chessboard with a fallen white king; the machine does not care which one it gets.

Rules as Code is the practice of writing a rule — a statute, a regulation, an internal policy — in a form a computer can execute, alongside the natural-language text, so that both are drafted, tested and kept in step together. The same idea travels under other names: Law as Code, Legislation as Code, machine-consumable legislation, computational law. The goal is not to automate judgment. It is to make the logic of a rule explicit, so it can be tested before it applies to anyone and reproduced after it has.

A runnable rule looks like this: facts go in, a question is asked, and the answer comes back with the article it rests on. Below is one such rule, a limitation period from an international instrument, with the facts, the questions and the answers, and links to run it with your own dates.

Where the term comes from

In 2018 New Zealand's Service Innovation Lab ran a three-week discovery with Inland Revenue, the Ministry of Business, Innovation and Employment and the Parliamentary Counsel Office, testing the approach on two existing pieces of legislation. Its report, Better Rules for Government, gave the movement its name.

In October 2020 the OECD's Observatory of Public Sector Innovation published Cracking the Code: Rulemaking for humans and machines, which proposed that some government rules exist in a machine-consumable version alongside the natural-language one, and set out what that asks of drafters, lawyers and engineers.

Several tools carry the idea. OpenFisca, developed in France since 2011 and released as free software, models tax and benefit rules and is used to simulate the effect of new law on households and the budget. Catala, from Inria and presented at ICFP 2021, is a programming language whose code follows the structure of the statute it implements; while encoding French family benefits its authors found a bug in the official implementation. Blawx, by Jason Morris, is a web-based tool for encoding and testing rules with answer set programming. In Germany, the federal agency SPRIND runs Law as Code as a strategic project aimed at official, machine-readable publication of legal norms.

Most of this work targets tax and benefits: who is eligible, and for how much. Contract law, time limits and procedure appear less often. The example below is a time limit.

A runnable example: when does a limitation period expire?

Article 10.2 of the UNIDROIT Principles of International Commercial Contracts (2016 edition) sets two periods. The general limitation period is three years, beginning on the day after the day the obligee knows or ought to know the facts that let it exercise its right. The maximum period is ten years, beginning on the day after the day the right can be exercised.

Take a case. The obligee learned the facts on 10 March 2020. The right could be exercised from 15 January 2019. Here is the test that sits in the package modelling chapter 10, trimmed to the facts that matter; the full file also names the parties and the contract:

test "PICCL-01-GENERAL-AND-MAXIMUM-PERIODS" {
    given {
        context {
            deadline_policy PICC_LIMITATION;
            legal_time @2026-09-17;
            timezone "UTC";
        }
        assert "a2": obligee_knew_facts_on(entity_ref("urn:case:piccl:right-1"), @2020-03-10) { origin case_input; }
        assert "a3": right_exercisable_from(entity_ref("urn:case:piccl:right-1"), @2019-01-15) { origin case_input; }
        assert "a4": general_period(entity_ref("urn:case:piccl:right-1"), 3 calendar_year) { origin case_input; }
        assert "a5": maximum_period(entity_ref("urn:case:piccl:right-1"), 10 calendar_year) { origin case_input; }
    }
    evaluate truth(general_period_expires_on(entity_ref("urn:case:piccl:right-1"), @2023-03-11));
    expect truth_status == TRUE_ONLY;
    expect any_applied(GeneralPeriodOfThreeYears);
}

Run the case and ask four questions:

Question Answer Why
Is the exercise of this right subject to limitation at all? Established Article 10.1(1)
Does the general period expire on 11 March 2023? Established Article 10.2(1): three years beginning on the day after 10 March 2020
Does it expire on 10 March 2023? Not established No rule makes that day the last one
Does the maximum period expire on 16 January 2029? Established Article 10.2(2): ten years beginning on the day after 15 January 2019

The third row is the one to read twice. "Not established" is not "false". The text says the count begins on the day after, so the model says so, and a question about the 10th finds no rule that concludes it. A reader who expected the 10th learns the difference from the model, not from a footnote.

Article 10.2: both periods begin on the day after the triggering day; the general period from the day the obligee knew, the maximum period from the day the right could be exercised. ARTICLE 10.2(1) · GENERAL PERIOD · THREE YEARS from 2020-03-11 · three years · beginning on the day after 2020-03-10 the obligee knows the facts 2023-03-10 Not established · no rule ends the period here 2023-03-11 expires · Established ARTICLE 10.2(2) · MAXIMUM PERIOD · TEN YEARS from 2019-01-16 · ten years · beginning on the day after 2019-01-15 the right can be exercised 2029-01-16 expires · Established The text says “beginning on the day after the day”, so the model counts from the day after. A question about the 10th finds no rule that concludes it: one day is an answer, not a footnote.
Article 10.2 as two timelines: the general period runs three years from 11 March 2020, the day after the obligee knew, and expires on 11 March 2023; a question about 10 March 2023 is not established. The maximum period runs ten years from 16 January 2019 and expires on 16 January 2029.

Now the second case: the period has expired, and the obligor has said nothing about it.

Question Answer Why
Is the right extinguished? Established: it is not Article 10.9(1)
Is its exercise barred? Not established Article 10.9(2): the obligor never asserted the expiry
May the obligee still set off? Established Article 10.10: until the expiry is asserted

Two answers that only look contradictory. The right survives, and its exercise is not barred either, because the bar needs an assertion that has not happened. Article 10.10 reads the same silence from the other side.

There is a third kind of answer. Where the Principles say "could not reasonably" or "fundamentally", the model does not decide. It returns a request for the tribunal's finding, with the article that calls for it. That is what the text asks for, and the answer says so in the same place it would otherwise give a result.

Three kinds of answer: established, with the article that applied; not established, because no rule concludes it; and a request for the finding the text calls for, addressed to the tribunal or the arbiter. FACTS OF THE CASE obligee_knew_facts_on(…) completed_illegal_move_count(…) evaluate one answer, always with the article it rests on ESTABLISHED a rule applied expires on 2023-03-11 article 10.2(1) the game is lost by White article 7.5.5 NOT ESTABLISHED no rule concludes it · not “false” expires on 2023-03-10 no rule makes that day the last the exercise is barred 10.9(2): the expiry was never asserted REQUEST FOR A FINDING the text calls for an assessment “could not reasonably” addressed to: the tribunal touched, meaning to move it? article 4.3 · addressed to: the arbiter Silence and judgment are answers of their own kind, given in the same place a result would be.
Three kinds of answer from one evaluation: established, with the article that applied; not established, because no rule concludes it; and a request for the finding the text calls for, addressed to the tribunal or the arbiter.

Run it yourself.

What an executable rule carries

Five things travel with every answer above, and they are what makes a rule executable rather than merely encoded.

  1. The text is pinned. Each article an answer cites is a fragment of the published text, fixed by a hash of its content. The model is written from that text and points back into it.
  2. Time is a parameter. Every question carries a date. The edition in force on that date answers, and a question asked of the 2024 text and of the 2026 text can get different results with the same facts.
  3. Silence and judgment are answers. "Not established" means no rule concludes it. "For the tribunal" comes back as a typed request, naming the article that requires the finding.
  4. The answer reproduces. An answer document holds the request, the chain of reasoning down to the articles, and the hashes of the model and the result. The verify page above runs it again and either matches or shows where it does not.
  5. The rule has tests. On 21 September 2026 the corpus of executable canons held 21,948 scenario files like the one above. They are written in one language and fail the way a broken unit test fails. The Law Has Unit Tests walks through one.

The same mechanics beyond the law

A statute, a standard, a rulebook and a textbook share one shape: an authoritative text with an edition and a provenance, applied to facts. Arxo executes the canon. Models formalize; Arxo executes and proves. Law came first because it is the most demanding case, not because the mechanics stop there.

Take the FIDE Laws of Chess, in force since 1 January 2023. Article 7.5.5 says that after a player's first completed illegal move the arbiter gives two minutes to the opponent, and that a second completed illegal move by the same player loses the game, unless the position is such that the opponent cannot checkmate by any possible series of legal moves, in which case the game is drawn.

Here is the case as the arbiter would record it: White has completed two illegal moves, and the record is complete on whether Black can still mate.

case SecondIllegal {
    assert "player": fide.laws.chess::player_of(entity_ref("urn:example:chess:game"), entity_ref("urn:example:chess:white")) { origin case_input; }
    assert "complete-mate-facts": fide.laws.chess::checked_player(entity_ref("urn:example:chess:white")) { origin case_input; }
    assert "illegal-count": fide.laws.chess::completed_illegal_move_count(entity_ref("urn:example:chess:white"), 2) { origin case_input; }
}
Case Question Answer
Two illegal moves, mate still possible Is the game lost by White? Established, by the rule on the second illegal move
Two illegal moves, no possible mate Is the game lost by White? Not established
Two illegal moves, no possible mate Is the game drawn? Established
A piece touched, no finding on intent Must White move it? A request to the arbiter: Article 4 turns on the intention, and the record does not state it

The board, the legality of a move and the possibility of mate are facts of the record. Arxo does not play chess. It applies the Laws to what the arbiter wrote down, and it names the arbiter where the Laws do.

Article 7.5.5 of the FIDE Laws of Chess as a decision path: the first completed illegal move gives the opponent two minutes; the second loses the game unless no checkmate is possible, in which case the game is drawn. The board and the possibility of mate are facts of the record. RECORD OF THE ARBITER completed_illegal_move_count(White, n) checked_player(White) record complete on whether Black can mate article 7.5.5 game_lost_by(game, White) how many completed? n = 1 two minutes extra time to Black the game goes on · no loss, no draw n = 2 can Black still mate? yes ESTABLISHED the game is lost by White no ESTABLISHED the game is drawn REQUEST FOR A FINDING article 4.3 · the intention is not in the record addressed to: the arbiter
Article 7.5.5 as a decision path over the arbiter's record: one completed illegal move gives Black two minutes; two illegal moves lose the game if Black can still mate and draw it if not; a touch whose intention is not in the record comes back as a request to the arbiter.

The Laws of Chess sit in the same corpus as the Principles and are served at the same public endpoint, https://mcp.arxo.io/mcp. Next to them: the IFAB Laws of the Game, with the goalkeeper's time limit across two editions; three HTTP RFCs and what happens to a Content-Length header; the CSS cascade from W3C, and which declaration wins. Each is modelled from its pinned text in the same language, and each answers with the section it rests on.

Questions people ask

Is Rules as Code the same as Law as Code? The same idea under two names. Rules as Code comes from the public-sector community around the New Zealand and OECD work and covers policy and regulation as well as statute. Law as Code is the name used in Germany and in much of the academic literature. Computational law is the broader academic term.

Does it replace lawyers or courts? No. It computes what follows from the text on the facts supplied. Where the text calls for an assessment, "reasonable", "fundamental", "intended", the answer is a request for that assessment, addressed to the tribunal or the arbiter, with the article that requires it.

What tools exist? OpenFisca for tax and benefit simulation; Catala, a language whose code follows the structure of the statute; Blawx, a visual tool over answer set programming; and Arxo, where the text is pinned by content, the edition is chosen by date, the answer reproduces by hash, and an AI agent can connect over MCP.

Can I use it from Claude, Cursor or Claude Code? Yes. One command adds the Principles as a server: claude mcp add --transport http picc https://mcp.arxo.io/mcp/picc. The MCP page lists the other endpoints and what an agent can ask.