Schemas and compatibility
The JSON Schemas that Lacuna packages for results, bundle manifests and audit profiles, the shape of a result document, and what the readers promise about versions.
Lacuna writes three kinds of persisted JSON: an analysis result, a bundle manifest and an audit profile. Each carries its own version field, and each has a JSON Schema shipped inside the package. A reviewer’s script, a dashboard or a CI job can read these files without importing Lacuna, and the version fields say which contract a file follows without guessing from a package number.
This page covers the packaged schemas, the shape of a result document, the compatibility manifest and what the strict readers enforce.
The packaged schemas
lacuna.schemas has four functions. Each returns the text of a file stored in the package. Calling one reads a resource and nothing else.
| Function | File | Describes |
|---|---|---|
lc.schemas.audit_result_v1_text() | audit-result-v1.schema.json | The AnalysisResult envelope: every result, every audit, every report’s JSON. |
lc.schemas.bundle_manifest_v1_text() | lacuna-bundle-manifest-v1.schema.json | The manifest.json inside a bundle. |
lc.schemas.standard_audit_profile_v1_text() | standard-audit-profile-v1.schema.json | The portable form of an AuditProfile, as to_dict() writes it. |
lc.schemas.persisted_artifact_compatibility_v1_text() | persisted-artifact-compatibility-v1.json | Not a schema: the compatibility manifest. |
The first three are JSON Schema documents for draft 2020-12. Their $id values are identifiers. Validate against the packaged text, not by fetching an address.
import json
import lacuna as lc
for loader in (
lc.schemas.audit_result_v1_text,
lc.schemas.bundle_manifest_v1_text,
lc.schemas.standard_audit_profile_v1_text,
):
document = json.loads(loader())
print(document["title"], "|", len(document["required"]), "required fields")
print(json.loads(lc.schemas.persisted_artifact_compatibility_v1_text())["format"]) Lacuna audit result v1 | 6 required fields
Lacuna reproducibility bundle manifest v1 | 8 required fields
Lacuna standardized audit profile v1 | 7 required fields
lacuna.persisted-artifact-compatibility lacuna doctor checks that each of the four files is present and carries the expected title or format, so a damaged install is reported. See lacuna doctor.
To validate a file, hand the schema to a Draft 2020-12 validator. Lacuna does not depend on one. This sketch uses the third-party jsonschema package, so it is not run here:
import json
import lacuna as lc
from jsonschema import Draft202012Validator
validator = Draft202012Validator(json.loads(lc.schemas.audit_result_v1_text()))
errors = list(validator.iter_errors(json.load(open("report.json")))) A schema validates the shape. The readers below also check what a schema cannot, such as duplicate keys. They are not a strict superset of the schemas, though: from_dict accepts some created_at spellings that the schema’s pattern rejects (20240101T000000Z), and the profile reader requires coverage_rule_version to be exactly 1 where the schema allows any positive integer. Validate with both.
Result JSON
Analytical functions return an AnalysisResult, or a wrapper such as a label or split result that holds one as .evidence, which you write with evidence.to_json(). Each result is written in a single envelope. AuditReport.to_json() writes the audit’s result in the same envelope. This is a complete result, with the timestamp removed because it changes on every run:
result = lc.AnalysisResult(
metadata=lc.ResultMetadata(
"example.check", method_version=1, parameters={"window": 20}, seed=7
),
metrics={"n": 3, "mean": 0.25},
findings=(
lc.Finding(
"EXAMPLE_FINDING",
"An example",
"Shown for its shape.",
lc.FindingState.WARN,
lc.Severity.LOW,
"example",
{"threshold": 0.5},
),
),
tables={"rows": [{"k": 1, "v": 0.5}]},
warnings=("A caveat.",),
)
document = json.loads(result.to_json())
document["metadata"].pop("created_at")
print(json.dumps(document, indent=2)) {
"findings": [
{
"category": "example",
"code": "EXAMPLE_FINDING",
"evidence": {
"threshold": 0.5
},
"message": "Shown for its shape.",
"severity": "low",
"state": "WARN",
"title": "An example"
}
],
"metadata": {
"input_fingerprint": null,
"method": "example.check",
"method_version": 1,
"parameters": {
"window": 20
},
"seed": 7
},
"metrics": {
"mean": 0.25,
"n": 3
},
"schema_version": "1",
"tables": {
"rows": [
{
"k": 1,
"v": 0.5
}
]
},
"warnings": [
"A caveat."
]
} | Field | Type | Meaning |
|---|---|---|
schema_version | "1" | The envelope version. The only value the reader accepts. |
metadata.method | string | What produced the result, such as signal.ic.spearman or audit.v0_1. Non-empty. |
metadata.method_version | integer, at least 1 | The version of that method’s logic. |
metadata.parameters | object | Every parameter the method resolved, so the result states how it was run. |
metadata.seed | integer at least 0, or null | The root seed of a randomized method. |
metadata.input_fingerprint | non-empty string or null | The identity of the input, when the method computed one. |
metadata.created_at | string | A UTC timestamp ending in Z, with optional fractional seconds. |
metrics | object | Named values, usually scalars such as counts, estimates and bounds. Any finite JSON value is allowed. |
findings | array | Zero or more findings, below. |
tables | object | Named tables, each an array of row objects or another JSON value. |
warnings | array of non-empty strings | Caveats about the method, such as an assumption that the data may violate. |
A finding has code, title, message, state, severity, category and evidence. The state is one of PASS, WARN, FAIL, UNKNOWN or NOT_APPLICABLE. The severity is one of info, low, medium, high or critical. All the others are non-empty strings except evidence, which is an object. Results explains how to read these.
The envelope, the metadata and each finding are closed: the schema sets additionalProperties to false, so an unknown field is an error, not an extension point. The open parts are parameters, metrics, tables and evidence, which hold any JSON value that is finite.
A few encoding rules follow from how results are built:
| Rule | Consequence |
|---|---|
A result refuses NaN and infinity when it is created. | JSON from Lacuna never contains them. A missing value is null, with a finding that says why. |
Dates and datetimes are converted to ISO 8601 strings, datetimes in UTC with a Z. A naive datetime is refused. | A table of dates is a table of strings. |
| Keys are sorted, and tuples and arrays are both arrays. | Output is deterministic for the same result. |
| Mapping keys must be strings. | A table keyed by integers is stored as rows. |
Reading results back
lc.AnalysisResult.from_json(text) parses a document and returns an immutable result. AnalysisResult.from_dict(mapping) does the same for an object you have already parsed. Both are strict. from_json also sees the raw text, so it alone can catch duplicate keys. Both reject non-finite values. Between them they reject:
| Problem | Example |
|---|---|
A missing or unexpected field, at the top level, in metadata or in a finding. | result fields do not match v1: missing=[...], unexpected=['a'] |
A schema_version other than "1". | unsupported result schema version '2' |
A duplicate key at any depth (from_json only). | result JSON contains duplicate object key 'metrics' |
NaN, Infinity or -Infinity. | result JSON contains non-finite constant 'NaN' |
An unknown state or severity, an empty required string, or a created_at that is not a UTC Z timestamp. | A reader error naming the field. |
Result and profile readers raise ValueError. The bundle readers (verify_bundle and BundleManifest.from_json) raise ReportError, which is a RuntimeError. A reader runs no code from the file: it parses JSON and builds values. A round trip loses nothing:
print(lc.AnalysisResult.from_json(result.to_json()) == result)
print(lc.AnalysisResult.from_json(result.to_json()).metadata.parameters["window"]) True
20 stored = json.loads(result.to_json())
stored["schema_version"] = "2"
lc.AnalysisResult.from_dict(stored) ValueError: unsupported result schema version '2' Profile JSON
An AuditProfile has a portable form: profile.to_dict() writes it and lc.AuditProfile.from_json(text) or AuditProfile.from_dict(mapping) reads it. It is the format of a custom standardized audit profile.
profile = lc.standard_profile("signal").to_dict()
print({key: profile[key] for key in profile if key != "requirements"})
print(profile["requirements"][0]) {'schema_version': '1', 'profile_id': 'standard.signal', 'profile_version': 1, 'scope': 'signal', 'scoring_model': None, 'coverage_rule_version': 1}
{'capability': 'signal_diagnostics', 'title': 'Signal and label diagnostics', 'category': 'statistical_validity', 'disposition': 'required', 'accepted_methods': ['labels.*', 'signal.*'], 'missing_severity': 'high'} | Field | Meaning |
|---|---|
schema_version | "1". |
profile_id, profile_version | A lowercase identifier made of letters, digits, dots, underscores and hyphens that starts with a lowercase letter, and a positive integer. |
scope | signal, strategy or options. |
scoring_model | Always null. A profile reports coverage and defines no score, and the reader rejects any other value. |
coverage_rule_version | Always 1. |
requirements | A non-empty array of capabilities, each with capability, title, category, disposition (required, optional or not_applicable), accepted_methods and missing_severity. |
accepted_methods are result method names, with at most one trailing * per pattern. The reader parses a profile without executing it: there is no code in the format, only names and dispositions to match against.
Bundle manifest JSON
manifest.json inside a .lacuna archive follows the bundle manifest schema. It declares the format (lacuna.reproducibility-bundle), bundle_version 1, the producer, the report’s identity, an artifact_set_sha256 digest and one entry per archive member except manifest.json itself, each with its path, role, media type, SHA-256 and size. Its security object records the trust contract: no executable code, no activated plugins, credentials and absolute paths redacted or rejected, source_data set to not_included_automatically. A reproducibility object records level identifiable, a scope of “artifact identity and archive integrity” and verified true.
lc.BundleManifest.from_json(text) parses a standalone manifest with the same strictness, rejecting duplicate keys, non-finite numbers and any field or value outside the version-1 contract. A parsed manifest says nothing about the archive that carries it. Use lc.verify_bundle to check the members and digests. Reproducibility bundles covers both.
The compatibility manifest
persisted-artifact-compatibility-v1.json states, for each persisted format, which version selector a reader looks at, which versions it accepts, and how an old one is handled.
manifest = json.loads(lc.schemas.persisted_artifact_compatibility_v1_text())
print(manifest["format"], manifest["manifest_version"], manifest["consumer_package_series"])
for contract in manifest["contracts"]:
print(
f"{contract['artifact']:<22} {contract['version_field']:<15}"
f" v{contract['source_version']} -> v{contract['target_version']}"
f" {contract['migration']:<8} {contract['reader']}"
)
print(f"{'':<22} producers {', '.join(contract['producer_package_series'])}") lacuna.persisted-artifact-compatibility 1 0.9
analysis_result schema_version v1 -> v1 identity lacuna.AnalysisResult.from_json
producers 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9
reproducibility_bundle bundle_version v1 -> v1 identity lacuna.verify_bundle
producers 0.7, 0.8, 0.9
standard_audit_profile schema_version v1 -> v1 identity lacuna.AuditProfile.from_json
producers 0.8, 0.9 | Field | Meaning |
|---|---|
artifact | The persisted format: analysis_result, reproducibility_bundle or standard_audit_profile. |
version_field | The field a reader selects on: schema_version for results and profiles, bundle_version for bundles. |
source_version, target_version | The version of the stored file and the version the current reader constructs. Both are 1. |
migration | identity: the stored bytes are validated under their original contract and read as they are. Nothing is rewritten, and no value is transformed. |
reader | The public function that reads this format. |
producer_package_series | The Lacuna release lines whose files this entry covers. |
consumer_package_series names the release line the matrix was published with, and it reads "0.9" in the matrix shipped with 0.14.3. The producer lists stop at 0.9 too, because the file has not been updated since. What it tells you holds today: results and profiles are at schema version "1" and bundles at version 1, and the readers accept exactly those.
What the readers promise
These are properties of the code that ships:
| Promise | How it shows |
|---|---|
| Compatibility is chosen by a version field, not by a package version or a file name. | The readers look at schema_version or bundle_version and nothing else. |
| An unsupported version fails closed. | unsupported result schema version, unsupported bundle version. There is no fallback parser and no defaulted field. |
| Persisted content is data, not code. | Readers parse JSON into values. They do not import plugins, activate entry points, unpickle or evaluate anything. |
| Evidence is not reinterpreted on read. | A stored finding keeps its state, severity, thresholds and method version. Reading never recomputes it. |
| Duplicate keys and non-finite numbers are errors. | A file that two parsers could read differently is rejected. |
These three formats are not the only JSON Lacuna writes. The benchmark record, the lacuna doctor payload and the bundle’s environment.json and redactions.json carry their own schema_version or benchmark_version fields, and none of them is described by the schemas above. The version of the envelope and the version of a method are separate. A result records its method and method_version, an audit also records every rule’s version and the score version, and a standardized audit records its profile identity and coverage-rule version. When the logic of a rule changes, old audits stay identifiable by their recorded versions, and Lacuna does not relabel them. Regenerate an old audit to get the current rules. The package version is not a compatibility selector for any of them.
Some things are not promised. The packaged schemas describe shape, not meaning: a valid file can still hold evidence that is weak or wrong. A matching schema version does not mean two results are comparable, because the method versions or parameters may differ. And Lacuna makes no claim about versions of these formats that do not exist yet.
The full signatures are in the lacuna.schemas API reference.