VIEW THIS AS

Auto mode follows the Route Engine until you choose a viewpoint.

YOU ARE HERE

ROUTE CHECK

CONNECTED TO

WHAT NEXT

Use the canonical route for this room, or HELP if you are unsure.

Vocabulary Coding and Engineering | Can Language Be Compiled into Rules? Building a Semantic Compiler with Tests

Educational illustration of a laptop, programming diagrams, notebook and network model

“Refund within 30 days” sounds precise until software has to decide what counts as a day, when the clock starts and what happens at the boundary. Does the period begin at purchase, delivery or activation? Are all goods included? Does a request made exactly at the deadline qualify? Is the shopper’s local timezone relevant? When a business converts a sentence into a program, each unanswered question becomes an implicit rule. This series calls the disciplined translation from human requirements into explicit, testable conditions a semantic compiler. Its purpose is not to pretend language can always be executed perfectly; it is to reveal the assumptions that software would otherwise silently invent.

A semantic compiler is an editorial design proposal, not a claim that an internationally standardised machine can automatically turn arbitrary sentences into correct laws. The approach combines plain-language analysis, domain expertise, structured definitions, rule implementation and tests. Real policy-as-code tools already exist: the Open Policy Agent documentation shows how teams write and test declarative rules, while IETF RFC 2119 illustrates why precise requirement words matter in technical specifications. This article explains the method at every zoom level, from one qualifier to a public institution, with a working audit readers can use before trusting automated decisions.

  • Word zoom: “Must”, “may”, “before” and “unless” can change a rule’s effect.
  • Sentence zoom: An apparently clear promise can conceal missing inputs and exceptions.
  • Definition zoom: A term needs a purpose, scope, owner and inclusion criteria.
  • Data zoom: Computer-readable fields must faithfully represent real-world evidence.
  • Rule zoom: Explicit conditions need ordinary and boundary-case tests.
  • Institution zoom: Approval, appeals and version changes remain human responsibilities.
  • Civilisation zoom: Automated policies can scale consistent help or systematic exclusion.

What does it mean to compile a sentence?

A programming-language compiler translates source code according to formally specified grammar and semantics. Natural language is different: words depend on context, speaker intention, shared assumptions and contested meanings. There is no general guarantee that a machine can translate a complex legal or ethical sentence into its one uniquely correct executable form.

The phrase semantic compiler is therefore a useful comparison rather than a literal replacement for legal drafting or human judgment. The process should stop when important information is missing, ask the right person to resolve the issue, record the choice and only then produce testable conditions. An honest failure state—“definition unresolved”—is better than a confident but arbitrary rule.

Zoom 1: one tiny word can invert a decision

Compare “Applicants may provide a reference” with “Applicants must provide a reference.” The first describes an option; the second imposes a requirement. “Applications submitted before midnight” may exclude an event at exactly midnight, while “by midnight” can be interpreted differently depending on the defined convention. These small expressions matter when automated systems determine eligibility.

RFC 2119 distinguishes words such as MUST, SHOULD and MAY in specifications explicitly adopting that convention. Its meanings do not automatically govern every employment contract or statute. Nevertheless, the engineering habit is transferable: identify obligation strength, timing, exceptions and who can waive a condition before writing code.

Zoom 2: build a requirement from observable inputs

Take the fictional sentence “Customers may receive a refund within 30 days.” The program cannot evaluate this safely without inputs: transaction date, product category, return condition, request timestamp, location, refund policy version and any exceptions. These are not just programming details. They determine who gets money.

A useful requirement identifies the outcome and conditions separately. For example: “For purchases covered by Policy A, requests received no later than 30 calendar days after the recorded delivery date are eligible for the standard review process, subject to the published exceptions.” This narrows uncertainty, but it still requires the specific calendar interpretation and evidence rules to be documented and reviewed before deployment.

Zoom 3: distinguish an input from an inference

Suppose a delivery company stores a status field called delivered. The program may treat that value as proof that the buyer received the item. But the field could mean the courier reached the address, left the parcel in a lobby or collected a signature. The record’s operational definition needs to match the relevant policy.

A semantic compiler must include data provenance: who recorded a state, what event it represents and whether it is disputed. Otherwise the software may faithfully apply a rule to the wrong facts. The W3C PROV overview provides a standard model for recording entities, activities and agents involved in generating information.

Zoom 4: separate the decision into facts, rules and consequences

A practical architecture has three layers. The facts layer stores observations or submissions with relevant source and quality. The rules layer evaluates conditions under a versioned policy. The consequences layer describes which action follows, including the chance to correct errors. Keeping the layers separate makes it easier to identify why an application was rejected.

For instance, an erroneous birth date is a data problem; an ambiguous age threshold is a rule-definition problem; an overly harsh automatic denial without review is a consequence and governance problem. A single generic status of “not eligible” hides these distinct routes to correction.

Zoom 5: what policy-as-code already does

The Open Policy Agent is a real policy engine using a declarative language called Rego. It allows applications to consult policy logic for decisions such as access control and configuration compliance. Its policy-testing documentation describes writing tests that evaluate how policy rules behave with specified input data.

That tooling is evidence that organisations can execute formally encoded policies, not proof that a program automatically knows what human language should mean. The quality of the output depends on the agreed rule, correct source data, system integration and tests. A syntactically valid rule can still faithfully implement an unfair or mistaken definition.

Zoom 6: a test case is a question about meaning

A good test does more than check whether a function runs. It verifies that a particular real-world situation receives the expected decision under the approved policy. For a refund rule, one test could cover a request comfortably within the window and another a request comfortably outside. Neither settles what happens at the exact boundary.

The hardest tests often involve missing records, contradictory information, different timezones and legitimate exceptions. These cases force the organisation to state the intended meaning. Test writing can therefore expose gaps in policy language before software amplifies them.

Zoom 7: a simple boundary matrix

  • Clearly included: A qualifying request made well before the deadline, with complete evidence.
  • Clearly excluded: An out-of-scope product under an explicit, lawful exclusion.
  • Exact boundary: A request submitted at the precisely defined cutoff time.
  • Missing data: A transaction record lacks a trustworthy delivery timestamp.
  • Conflicting data: Customer and carrier records show different handover dates.
  • Exceptional case: The policy provides an authorised extension or accessibility accommodation.
  • Changed rule: The request concerns a purchase made under an older policy version.

A strong implementation has a documented expected handling for each case. Some outcomes may require a human review or a request for evidence rather than an automatic yes or no. If the policy author cannot answer a test case, a programmer should not quietly choose the most convenient interpretation.

Zoom 8: not every value should be Boolean

Software teams often use simple labels such as true or false. But some concepts have additional states: pending, incomplete evidence, in review, rejected on specified grounds or superseded. Collapsing all these into “no” may deny services to people whose cases were never properly evaluated.

A better state model represents uncertainty where it matters. For instance, “eligibility unconfirmed pending documentation” is different from “eligibility assessed and denied”. This distinction is especially important in public benefits, medicine, financial services and legal processes where a negative result can have serious consequences.

Zoom 9: preserve the human-readable source

Every executable rule should link back to the exact version of the requirement or governing policy that authorised it. When the code is updated, reviewers should verify that the plain-language explanation and test cases still match. A code review that checks only performance or syntax can miss a changed interpretation of the underlying promise.

The record should include the rule owner, source document, effective dates, approved exceptions and tests. Sensitive personal data should not be copied unnecessarily into permanent public audit logs. Integrity is useful when it supports accountable decisions; excessive data preservation can create privacy and fairness risks.

Zoom 10: the problem of a hidden default

A requirement does not specify what to do when a customer has not submitted a required document. The program must still return some state. A careless implementation may default to denial, approval or indefinite waiting without notifying the person. Each choice has consequences, and one may be inconsistent with the applicable legal duty.

The semantic compiler should surface such missing branches as explicit questions for the authorised owner. What is the time allowed to complete an application? Must the person receive notice? Can they correct a mistake? When does the decision become final? These are governance choices, not mere programming conveniences.

Zoom 11: why an accurate interface matters

A system may display “approved” before payment or access is actually authorised. Another may show “failed” when the application is still under review. The interface vocabulary then makes the system appear to have reached a decision it has not made. Accurate status text should describe the operation and its next step, not just borrow a comforting adjective.

If the system can produce a machine-readable decision, the reader should be able to understand the corresponding human-readable explanation. “Your request is under review because supporting evidence is missing” is better than a status simply saying “error”. Clarity helps users correct problems without guessing what the program intended.

Zoom 12: test the rule against its opposite

One way to detect unintended logic is to create pairs of cases that differ in one decisive fact. If a benefit requires residence in a defined area, compare otherwise identical hypothetical applicants inside and outside that area. If a policy excludes only certain goods, compare one included and one excluded category. The result should change when the authorised condition changes and remain stable when irrelevant facts change.

This is a counterfactual test of the rule, not a judgment that the underlying policy is fair. A discriminatory policy can be applied consistently. Technical tests and ethical/legal review are distinct responsibilities, and both may be needed.

Zoom 13: test the language of the explanation

A policy engine may make the correct decision while giving users a misleading explanation. It might say “You failed the eligibility test” when the actual status is “We could not verify a required record.” The first suggests the user is definitively ineligible. The second makes the uncertainty visible and directs attention toward correction.

The semantic spine of an explanation should preserve the applicable rule, factual basis, uncertainty, next step and review route. An AI system that rewrites explanations must be checked for changes in obligation, dates or certainty. A friendly paraphrase is not harmless if it silently removes an appeal option.

Zoom 14: when policy versions collide

Suppose the refund rule changes from 30 to 45 days. Does the new policy apply to purchases made earlier? Only to future purchases? To pending requests? The answer depends on the authorised transition arrangements. A system that replaces the number without documenting the effective date may incorrectly reclassify old cases.

Version control should preserve both rules and the events governed by each. A change log records the reason, tests, authority and users affected. Historical metrics should be interpreted under the definitions that applied at the time, or recalculated transparently when the underlying records permit it.

Zoom 15: social values do not compile into a neutral formula

Terms such as “reasonable”, “fair”, “safe”, “proportionate” or “respectful” may require contextual judgment and legal interpretation. A system can implement specified criteria, but it cannot honestly claim to eliminate every value judgment by assigning numbers to those words. If a policy has discretion, the automated design should show where and how authorised people exercise it.

The objective is not to turn every human decision into code. It is to automate the parts that are reliably defined and verifiable while preserving human responsibility, proportional review and the possibility of contesting the policy itself.

A practical ten-field semantic rule card

  • Requirement: The exact approved sentence and source.
  • Purpose: The real-world decision or protection it is intended to support.
  • Authority: Who may define and revise the rule.
  • Inputs: Which data, units, sources and timestamps are required.
  • Criteria: Inclusion, exclusions, thresholds and exceptions.
  • Uncertainty: How unknown, conflicting or disputed data are handled.
  • Action: What the system does when the rule is satisfied or not.
  • Explanation: What the affected person is told.
  • Tests: Ordinary, boundary, missing-data and version-transition cases.
  • Correction: Review, appeal, rollback and audit arrangements.

A seven-step vocabulary-to-code workflow

  1. Collect the human-language requirement from the authoritative source.
  2. Mark ambiguous words and ask the owner to define their intended meaning.
  3. Create inclusion, exclusion and difficult boundary examples.
  4. Specify the evidence and exact data types needed for the decision.
  5. Implement the rule in an appropriate, reviewable policy system.
  6. Run tests covering normal cases, adversarial errors, changed inputs and exceptions.
  7. Have qualified reviewers verify both executable behaviour and the human explanation before release.

Frequently asked questions

Can AI automatically convert laws into perfect executable rules?

No. AI may help structure or propose rule candidates, but legal ambiguity, contested interpretation, missing facts and value judgments require authorised human review. A program’s successful execution does not establish legal validity.

What does a policy-as-code tool actually prove?

It can evaluate conditions and support repeatable tests under a defined software implementation. It does not prove that the underlying policy is fair, complete, current or appropriately applied to the real world.

Why are boundary cases so important?

Definitions often appear clear until an example lies exactly at a threshold or involves conflicting evidence. Boundary tests expose hidden decisions that ordinary examples do not reveal.

What if the definition cannot be made completely precise?

Document the uncertainty and create a proportionate human review process rather than inventing an arbitrary automated yes/no answer. A safe system may need a “requires assessment” state.

Conclusion: compile the definition, not an unexamined assumption

At the word zoom, “within” and “before” carry different boundaries. At the sentence zoom, a simple promise conceals hidden questions. At the software zoom, those questions become conditions, defaults and consequences. At the civilisational zoom, the same logic may govern large numbers of people. Vocabulary Coding and Engineering is most valuable when it refuses to let code silently answer policy questions that humans have not resolved. The aim is not software that looks decisive; it is rules whose meaning, authority, evidence and consequences can actually be inspected and corrected.

Sources and related reading

Editorial note: “Semantic compiler” is an educational design metaphor developed for this series, not a standardised product or proof that arbitrary natural language can be automatically turned into correct law or software. All examples are illustrative and must not be used as a real refund, eligibility or legal policy without review.