Search across all content
Rules as Code (RaC) is a revolutionary approach to rulemaking that encourages governments to create a trustworthy version of rules in a machine-consumable form.
This information was sourced from "New Techniques for Building and Using Legal Encodings in the Drafting Room" by Observatory of Public Sector Innovation (OECD), https://oecd-opsi.org/innovations/new-techniques-for-building-and-using-legal-encodings-in-the-drafting-room/. Licensed under Creative Commons Attribution-ShareAlike 3.0 IGO (CC BY-SA 3.0 IGO).
Rules as Code (RaC) is a revolutionary approach to rulemaking that encourages governments to create a trustworthy version of rules in a machine-consumable form. When rules are encoded in a clear, tangible, consistent manner, and made publicly available, they can be used to power legal automation, simulation, and verification tools. This could significantly enhance public service delivery while simultaneously providing more transparency on government decision-making.
The Canada School of Public Service (CSPS) has been running RaC experiments since 2019. For our first projects, we selected laws that were descriptive, interconnected, expansive, and subject to frequent change. We then asked a multidisciplinary team of experts to convert these rules into code using the microsimulation tool OpenFisca. These initial experiments supported our hypothesis that encoded rules could significantly enhance public service delivery. However, we also identified some major obstacles. For example, interpreting the meaning of existing rules in order to convert them into code was challenging. Furthermore, the interdisciplinary nature of the workgroup (e.g. drafters, subject matter experts, coders) presented communication challenges. Finally, it is very difficult to capture the whole meaning of a law using imperative programming languages like OpenFisca.
These lessons prompted us to think of ways to make RaC more appealing to rule-makers, which led to two innovations.
Our first innovation – Blawx – is an open-source and user-friendly programming tool designed specifically to help non-programmers encode, test, and use rules. Blawx is powered by a predicate declarative logic software called s(CASP) and overlayed with a visual programming interface (Blockly). It has a user-friendly simulation interface, provides detailed explanations for answers, and can execute hypothetical reasoning tasks. Blawx is being developed in collaboration with Canadian public service professionals, so that it can help fill the developer-user gap we have identified in the RaC space.
Our second innovation – a rule-drafting methodology – was developed in collaboration with the Treasury Board of Canada Secretariat (TBS). The TBS wanted to apply a RaC approach to help draft a “Definition of Salary” regulation that clearly outlines and integrates desired policy outcomes under the Public Service Superannuation Act. In the first stage of the experimentation, TBS used RaC to test whether or not regulation was the proper policy tool to meet their desired outcomes. This was an excellent case study for RaC, as these rules were complicated, and applied to different collective agreements and payment codes. Using our Blawx prototype, we co-drafted the policy proposal into code and tested it with subject matter experts. The rule encodings could then be reused in the drafting room to help the subject matter experts communicate with the legal drafters who are writing the official regulations.
This project has resulted in the following two innovations:
To our knowledge, this would be the first time that:
We have completed the policy exercise phase. By drafting, encoding, and testing different regulatory text proposals, we were able to identify ambiguities and gaps to discuss with legal drafters. It also helped us identify elements that needed to be corrected in the Blawx software. Our next step is the regulatory drafting phase, where we will test the encodings alongside legal drafters.
Once the rules and their associated encodings have been finalized, we will investigate the feasibility of publishing our rule encodings for consultation in the Canada Gazette alongside the official English and French versions. However, the encodings should not be viewed as having equal legal status to the official rules. Rather, they are trustworthy interpretations of rules that can help communicate their meaning to citizens and stakeholders, as governments strive to offer improved service delivery.
The Treasury Board of Canada Secretariat (TBS) conceptualized the project and provided the subject matter expertise. The Canada School of Public Service (CSPS) provided the Rules as Code expertise. The initial encodings were drafted by a lawyer-turned-developer at the CSPS, and Blawx was built by a legal computational expert. We are teaching subject matter experts from the TBS how to write the encodings themselves, and we are considering undertaking a similar exercise with legal drafters.
Encoded rules can help anyone who implements, or is subject to, the rules. When governments have a trusted set of encoded rules, they can more effectively conduct administration, evaluation, and compliance activities. The rules encoded in this project could help support better service delivery of Canada’s federal pensions program, by providing members with clearer and more transparent information on how their pensions are calculated.
This project reaffirmed that writing a set of rules into code will reveal ambiguities, loopholes, and gaps that often go unnoticed when reading and writing laws only in natural languages. We hope the time we spent meticulously writing out the rules into code during the policy phase will help parties more efficiently and effectively develop comprehensive and clear rules in the drafting room. The encodings could be repurposed by future rule-makers when amendments are made at a later date. If rules are encoded and shared publicly via an Application Programming Interface (API), we believe this will help others implement them in a more streamlined, comprehensive, and consistent manner.
Ideally, a rule should be encoded at inception alongside subject matter experts and legal drafters who know it best, and potentially in the drafting room. However, most RaC tools are designed for programmers, and legal and policy professionals rarely have backgrounds in the computer sciences. The biggest challenge in the RaC space is finding ways to make the practice more accessible to rule-makers. While the tool we used (Blawx) is designed with this audience in mind, it is still a prototype that requires further development before deploying. We also faced some challenges navigating the use of experimental software in the federal public service, and familiarizing ourselves with Canada’s new Guide on the use of Generative AI.
If you would like to use existing RaC tools within your organization, it is important to first identify the rules you would like to write into code, and then assemble a multidisciplinary team of professionals with overlapping skillsets in the areas of legislative and contractual drafting, symbolic AI, and generative AI. In both instances, it is highly recommended that you get support from leadership in your organization so you can get the required resources for your RaC project. Invest your time in building the right pitch and presenting it to the right people.
Rules as Code is a relatively new practice, but there are experiments being conducted in this space around the world. In Canada, we are conducting another RaC experiment with Natural Resources Canada, where rules pertaining to the mining permit process are being converted into code and fed into consumer-facing applications via an API. We are also collaborating with Justice Canada to explore ways to tailor RaC tools for legal drafters. However, what makes this case study unique is that we are using a RaC approach to craft new rules, not just converting existing ones. As with all RaC projects, the encodings are designed to be repurposed and reused in the future, making replication easy.
While the initial rule encodings for this project were drafted by the lawyer-turned-developer at the Canada School Public Service, the latest regulatory text proposals were encoded by a pensions subject matter expert from the Treasury Board of Canada Secretariat. We are also exploring the possibility of supporting a regulatory drafter with how to respond to the proposed drafting instructions in code, using Blawx. Lastly, it is worth noting that this project was a distributed team effort. While most contributors were located in the National Capital Region (Ottawa, Ontario), many resided in other provinces.
Budget: Not disclosed





Connect with 500,000+ public servants solving your hardest challenges.





Connect with 500,000+ public servants solving your hardest challenges.
Help public servants worldwide learn from your work, what worked, what flopped and what you'd do differently
Share your project
Log in or sign up to continue the conversation