Skip to content
An official website of the OECD. Find out more
Created by the Public Governance Directorate

This website was created by the OECD Observatory of Public Sector Innovation (OPSI), part of the OECD Public Governance Directorate (GOV).

How to validate authenticity

Validation that this is an official OECD website can be found on the Innovative Government page of the corporate OECD website.

New Techniques for Building and Using Legal Encodings in the Drafting Room

The Government of Canada is experimenting writing existing laws and proposed regulations into code. Encoding rules allows us to run legal simulations in the regulatory drafting room, which helps us detect ambiguities, loopholes, and gaps in the rules that often go unnoticed. However, existing tools designed by and for programmers are not intuitive for rule-makers. In response, we set out to develop one – an open-source Rules as Code tool called Blawx.

Innovation Summary

Innovation Overview

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.

Innovation Description

What Makes Your Project Innovative?

This project has resulted in the following two innovations:
1. The development of a RaC tool called Blawx that makes the practice of encoding laws accessible to non-programmers; and,
2. The development of a rule-drafting methodology that is intended to enable policy experts, lawyers, IT developers, and legal drafters to more effectively communicate their expertise through code in the drafting room, and to the public once published.

To our knowledge, this would be the first time that:
1. Rules as Code has been used by Canada (or in Canada) to support legal/policy decision-making;
2. Answer set programming (ASP) is used for legal/policy decisions;
3. The code was written primarily by a non-programmer;
4. The code was deployed to answer the question "should a regulation be written for X"; and,
5. The code is used in a real-world legislative task.

What is the current status of your innovation?

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.

Innovation Development

Collaborations & Partnerships

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.

Users, Stakeholders & Beneficiaries

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.

Innovation Reflections

Results, Outcomes & Impacts

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.

Challenges and Failures

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.

Conditions for Success

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.

Replication

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.

Lessons Learned

1. Encoded rules make legal automation, simulation, and verification possible.
2. Writing rules into code during the drafting process helps reveal gaps, loopholes, and ambiguities that may otherwise go unnoticed when reading and writing the natural language on its own.
3. Encoded rules are more trustworthy if they are written at their inception and by the rule-makers, using tools that improve communication between participants.
4. Rules as Code can be conducted by non-programmers, but work is still needed to promote its benefits and make it more appealing to this audience.

Anything Else?

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.

Year: 2023
Level of Government: National/Federal government

Status:

  • Developing Proposals - turning ideas into business cases that can be assessed and acted on
  • Implementation - making the innovation happen
  • Evaluation - understanding whether the innovative initiative has delivered what was needed
  • Diffusing Lessons - using what was learnt to inform other projects and understanding how the innovation can be applied in other ways

Innovation provided by:

Date Published:

22 July 2024

Join our community:

It only takes a few minutes to complete the form and share your project.