OpenVDL: Making Validation Rules Readable and Traceable

  • Post published:

The part of validation I keep coming back to is what happens after the check has been written. A rule looks straightforward inside one application. Once several services depend on their own versions of it, a small change raises larger questions: who else uses this assumption, and will they interpret it the same way?

In my work at Openapi SpA, dealing with data from different sources has made those questions feel very practical. I want to be able to follow a rule back to its definition and understand why it is there. That is the motivation behind OpenVDL, the Open Validation Description Language, a v0.1 draft open specification for representing validators as portable documents.

Starting with a rule I can explain

Consider an IBAN moving from a form to a backend and then into a batch job. Imagine that each system gives a different answer. Before changing any code, I would want to put the three definitions side by side. Do they normalize the input the same way? Are they checking the same constraints? Which version of the format do they assume?

OpenVDL starts from the idea that this definition deserves its own document. An engine would interpret it in the application’s language, while the rules would remain available for everyone to read and review.

Reading the checks in order

The project’s IBAN example is a useful place to begin. This excerpt describes the steps a reader would expect to discuss when reviewing the rule:

openvdl: "0.1"
id: "openvdl/iban"
version: "1.0.0"
input:
  type: string
normalization:
  - type: stripWhitespace
  - type: uppercase
stages:
  - id: structure
    rules:
      - { id: iban.charset, type: pattern, engine: regex, value: "^[A-Z0-9]+$" }
      - { id: iban.min-length, type: minLength, value: 15 }
      - { id: iban.max-length, type: maxLength, value: 34 }
  - id: checksum
    rules:
      - { id: iban.mod97, type: algorithm, name: mod97, expect: 1 }

I can follow the sequence without opening an implementation: remove whitespace, uppercase the letters, check the shape, apply Mod 97. I can also see what is missing. The example does not cover the required length and structure for each country. Making a rule readable gives another person a chance to notice those gaps and explain how to fill them.

The draft defines VALID for checks that pass, INVALID for a failed rule, and ERROR when evaluation cannot finish. I find that last distinction particularly useful. If an engine cannot resolve a required validator, the application needs to know that it has no answer. A rule ID in the diagnostic can help a maintainer find the part of the definition that needs attention.

Leaving room for the next requirement

The next requirement is often small. Imagine that an internal service should accept only addresses at acme.com. I would like to keep that decision close to the service’s policy while retaining a reference to the shared email rules. This excerpt from the extension example shows the proposed approach:

openvdl: "0.1"
id: "acme/email"
version: "1.0.0"
extends:
  - "openvdl/email@1"
stages:
  - id: acme-policy
    rules:
      - { id: acme-domain-only, type: domainEquals, value: acme.com }

Reading it, I can tell where the base rules come from and where the local restriction begins. Later, someone changing that restriction would have a named, versioned document to review. They would still need to check the dependency, but they would have a clear place to start.

A different requirement is choosing a validator by country. The VAT example declares the input fields and imports national definitions, then routes them here:

compose:
  match:
    field: country
    cases:
      - { equals: IT, ref: "openvdl/vat/it@1" }
      - { equals: DE, ref: "openvdl/vat/de@1" }
      - { equals: FR, ref: "openvdl/vat/fr@1" }
    default:
      error:
        code: unsupported-country

The unsupported-country result is ERROR: there is no applicable definition to consult. These snippets describe the draft’s intended behavior. They are material for discussion, rather than evidence of a complete implementation running today.

Remembering why a check exists

The part I most want to develop is the record behind a rule. A registry changes its format. A numbering plan expands. Someone checks the source and updates the validator. Months later, another maintainer encounters the new constraint and has to work out why it exists.

OpenVDL proposes keeping relevant facts inside the document, including their source, impact, confidence, and effective date. The model is still taking shape. My hope is that someone opening a validator later can recover enough of the reasoning to make the next change with confidence.

That also gives contributors a useful starting point. Knowing a particular identifier well, including its awkward exceptions, can be as valuable to this work as knowing how to build an engine.

That idea has a history. LIVR already describes portable rules in JSON; JSON Schema offers constraints and composition. libphonenumber and python-stdnum show how much knowledge identifier validation requires. What interests me is bringing the checks and their supporting knowledge together in a shared, versioned format.

Writing a request for comments

Writing OpenVDL in an RFC-style format for the first time brought an unexpected mix of excitement and pride. It also made me pay closer attention to statements that felt obvious in conversation. Once written as a requirement, a sentence has to give another implementer enough information to act on it.

There is plenty left to clarify. Consistent results across languages need shared test vectors, precise semantics, and independent implementations. OpenVDL has not been submitted to the IETF and is not an IETF standard; we intend to submit an individual Internet-Draft after a first round of feedback.

The repository contains the draft and examples. I would welcome a validator for a format you know, a test case that exposes an ambiguity, or an issue explaining where the model falls short. Those are the conversations I hope this draft starts: people bringing their own experience to a rule we can read together.

The post OpenVDL: Making Validation Rules Readable and Traceable appeared first on Linux.com.