Published Spec Contract Reference
The exact schema of
published_versions.spec— the data contract written by SmartRules and consumed by eApproval, the Portal, and integrations.
1. Overview
When SmartRules publishes a procedure, it writes a single JSON blob into published_versions.spec. This blob is an append-only snapshot: it freezes the procedure definition at publish time and becomes the canonical contract for every downstream consumer.
Key properties:
- Immutable — once published, the spec never changes. New publishes create new
published_versionsrows. - Self-contained — every consumer must be able to operate from the spec alone, without querying SmartRules tables.
- Defensively consumed — all runtime code uses
.get()with sensible defaults. The Pydantic modelFormSchemaV1is used only at the public API boundary. - Backward-compatible — new keys are additive. Legacy specs missing newer keys are tolerated.
Current schema version: 1 (hard-coded in smartrules/publishing.py).
2. Top-Level Structure
{
"schema_version": 1,
"procedure": { ... },
"agency": { ... },
"total_requirements": 5,
"sections": [ ... ],
"registry": { ... },
"trust_progression": { ... },
"requirements": [ ... ],
"roles": [ ... ],
"edges": [ ... ],
"evaluation_criteria": [ ... ],
"filters": [ ... ],
"event_bindings": [ ... ],
"integration_standards_compliance": { ... }
}
| Key | Required | Added | Description |
|---|---|---|---|
schema_version | Yes | Plan 2 | Always 1 |
procedure | Yes | Plan 1 | Procedure metadata |
agency | Yes | Plan 1 | Agency reference |
total_requirements | Yes | Plan 1 | Count of requirements |
sections | Yes | Plan 1 | Display-oriented requirement grouping |
registry | No | Plan 2 Task 11 | Registry contract block |
registry_entities | No | D26 Phase C Task 2 | One block per repeating group bound to a typed child entity |
trust_progression | No | Plan 2 Task 11 | State machine definition |
requirements | No | Plan 2 Task 11 | Registry-column-oriented requirement list |
roles | Yes | Plan 1 | DAG nodes |
edges | Yes | Plan 1 | DAG edges |
evaluation_criteria | Yes | Plan 1 | Checklists per role/requirement |
filters | Yes | Plan 1 | Display filters |
event_bindings | No | Phase 2B | Snapshotted SmartLink event bindings |
integration_standards_compliance | No | Phase 2B | Binding compliance summary |
Backward compatibility:
registry,trust_progression,requirements,event_bindings, andintegration_standards_complianceare all optional because specs published before Phase 2B/Plan 2 Task 11 do not contain them. Consumers must use.get()with defaults.
3. Block-by-Block Reference
3.1 procedure
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"name": "Register a Business",
"description": "Commerce registration procedure",
"legal_basis": "Commerce Act 2024",
"category": "Business",
"version": 3,
"verification_mode": "application",
"max_correction_depth": 3
}
| Field | Type | Default | Description |
|---|---|---|---|
id | str (UUID) | — | Procedure primary key |
name | str | — | Human-readable title |
description | str | null | null | Long-form description |
legal_basis | str | null | null | Legal authority |
category | str | null | null | Category label |
version | int | — | Monotonically increasing publish counter |
verification_mode | str | "application" | "application" or "claim" |
max_correction_depth | int | 3 | Max correction loops before terminal rejection |
Consumers:
published/routes.py—procedure.namefor public listingeapproval/routes.py—procedure.namefor application list itemseapproval/projections.py—procedure.verification_mode(default"application")eapproval/routes.py—procedure.max_correction_depth(default3)eapproval/notification_threads/inbox_service.py—procedure.namefor inbox display
3.2 agency
{
"id": "550e8400-e29b-41d4-a716-446655440001"
}
| Field | Type | Description |
|---|---|---|
id | str (UUID) | Agency primary key |
Note: The agency ID and
nameare stored directly, not resolved at runtime.country_codeis also stored as of D26 Phase C Task 2 (smartrules/publishing.py:1698) — it scopesregistry_entities(see §2’s row above; shape documented indocs/specs/embedded-mode-contract.md) the same wayregistry.country_codealready scopes the embedded-mode top-level table (§3.5 below). Any other agency metadata beyond these three fields is still resolved at runtime via thedeploymentsregistry or cached separately.
3.3 total_requirements
An integer equal to len(requirements) at publish time. Used by the Portal for progress indicators.
3.4 sections
Display-oriented grouping of requirements. Requirements are grouped by their section name (default "General").
[
{
"title": "Business",
"requirements": [
{
"id": "550e8400-e29b-41d4-a716-446655440002",
"field_name": "businessName",
"field_type": "text",
"label": "Business Name",
"description": "Official registered name",
"section": "Business",
"sort_order": 1,
"is_required": true,
"condition": null,
"formal_criteria": { ... },
"substantial_criteria": null,
"labels": null,
"standard_ref": null,
"variants": null,
"field_capabilities": { ... }
}
]
}
]
SectionRequirement fields:
| Field | Type | Description |
|---|---|---|
id | str (UUID) | Requirement primary key |
field_name | str | CamelCase identifier (used as form key) |
field_type | str | text, number, date, boolean, yes_no, list, document, email, phone, address |
label | str | Human label |
description | str | null | Helper text |
section | str | null | Grouping name |
sort_order | int | Display order within section |
is_required | bool | Whether the field is mandatory |
condition | str | null | JSONata or conditional expression |
formal_criteria | object | null | Proof modes, rules, binding config |
substantial_criteria | object | null | Substantive evaluation criteria |
labels | object | null | i18n label overrides |
standard_ref | str | null | Reference to external standard |
variants | object | array | null | Variant definitions |
field_capabilities | object | null | Publish-time resolved SmartLink metadata |
Consumers:
- Portal — renders forms from
sections[].requirements[] published/lookup_routes.py— resolves field lookups byfield_nameeapproval/bots.py— collects API proof modes fromformal_criteriaeapproval/registry_view.py— fallback column derivation whenrequirementscontract block is absent
3.5 registry
The registry contract block defines how the published procedure maps to a physical registry table.
{
"table_name": "ls_register_a_business",
"primary_key": "reference_number",
"status_vocabulary": [
"submitted",
"pending_commerce_review",
"pending_tax_review",
"registered"
],
"registered_state": "registered",
"country_code": "LS"
}
| Field | Type | Derivation |
|---|---|---|
table_name | str | {country_code.lower()}_{slugify(procedure.name)} |
primary_key | str | Hard-coded "reference_number" |
status_vocabulary | array[str] | ["submitted"] + pending_<role> per topo order + ["registered"] |
registered_state | str | Hard-coded "registered" |
country_code | str | Agency.country_code |
Status vocabulary derivation:
- Start with
["submitted"] - Append
"pending_<slugified_role_name>"for each verification role in DAG topological order - Append
["registered"]
Example: If verification roles are
commerce_reviewthentax_review, the vocabulary is["submitted", "pending_commerce_review", "pending_tax_review", "registered"].
Consumers:
eapproval/registry_view.py— contract-based column derivation- External integrations — table name for registry sync
3.6 trust_progression
State machine metadata derived from the registry vocabulary.
{
"states": [
"submitted",
"pending_commerce_review",
"pending_tax_review",
"registered",
"rejected"
],
"initial_state": "submitted",
"terminal_states": ["registered", "rejected"]
}
| Field | Type | Derivation |
|---|---|---|
states | array[str] | status_vocabulary + ["rejected"] |
initial_state | str | "submitted" |
terminal_states | array[str] | ["registered", "rejected"] |
3.7 requirements (contract block)
The registry-column-oriented view of requirements. This block has a different shape from sections[].requirements[] — it is optimised for database schema generation and state transition tracking.
[
{
"id": "550e8400-e29b-41d4-a716-446655440002",
"field_name": "businessName",
"field_type": "text",
"label": "Business Name",
"section": "Business",
"registry_column": {
"name": "business_name",
"logical_type": "text",
"max_length": 255,
"nullable": false,
"status_column": "business_name_status",
"initial_status": "submitted"
},
"state_transitions": [
{
"from": "submitted",
"to": "pending_commerce_review",
"role": "550e8400-e29b-41d4-a716-446655440010",
"action": "assert"
}
]
}
]
ContractRequirement fields:
| Field | Type | Description |
|---|---|---|
id | str (UUID) | Requirement primary key |
field_name | str | CamelCase identifier |
field_type | str | Same as SectionRequirement |
label | str | null | Human label |
section | str | null | Grouping name |
registry_column | object | Column definition (see below) |
state_transitions | array[object] | Per-requirement state transitions |
registry_column sub-block:
| Field | Type | Derivation |
|---|---|---|
name | str | _snake_case(field_name) |
logical_type | str | Mapped from field_type (see mapping table) |
max_length | int | omitted | 255 for text types |
precision | int | omitted | 18 for number |
scale | int | omitted | 4 for number |
nullable | bool | not is_required |
status_column | str | {name}_status |
initial_status | str | "submitted" |
Logical type mapping:
SmartRules field_type | Registry logical_type |
|---|---|
text, list, document, email, phone, address | text |
number | decimal |
date | date |
boolean, yes_no | boolean |
state_transitions sub-block:
| Field | Type | Description |
|---|---|---|
from | str | Previous state |
to | str | Next state |
role | str (UUID) | Role ID that triggers this transition |
action | str | Always "assert" in current implementation |
Transitions are derived per-requirement based on which verification roles are assigned to it. A role with empty assigned_requirement_ids is treated as “all requirements.”
Consumers:
eapproval/registry_view.py— primary contract-based registry view
3.8 roles
DAG nodes. Each role becomes a gate in eApproval.
[
{
"id": "550e8400-e29b-41d4-a716-446655440010",
"name": "Commerce Review",
"abbreviation": "COM",
"role_type": "official",
"node_type": "verification",
"agent_type": "human",
"agent_composition": "single",
"method": null,
"institution_id": null,
"precondition_ids": [],
"assigned_requirement_ids": [],
"sla_days": 5,
"sla_day_kind": "calendar_days",
"quorum": null,
"sort_order": 1,
"can_reject": false
}
]
| Field | Type | Description |
|---|---|---|
id | str (UUID) | Role primary key |
name | str | null | Human name |
abbreviation | str | null | Short code |
role_type | str | null | official, system, etc. |
node_type | str | null | verification, automation, convergence |
agent_type | str | null | human, bot |
agent_composition | str | null | single, quorum |
method | str | null | Execution method hint |
institution_id | str | null | External institution reference |
precondition_ids | array[str] | UUIDs of roles that must complete before this one |
assigned_requirement_ids | array[str] | UUIDs of requirements this role verifies (empty = all) |
sla_days | int | null | Service-level agreement |
sla_day_kind | str | D57: what sla_days counts in — calendar_days or working_days. Never null on a published snapshot: an unconfirmed authoring choice writes as calendar_days (spec D-10). |
quorum | int | null | Required approver count |
sort_order | int | null | Display/tiebreak order |
can_reject | bool | null | Whether this role may issue a definitive no (Rule 2 renamed can_terminate) |
Consumers:
eapproval/dag.py— DAG computation (topological sort, start roles)eapproval/routes.py— claim validation, role existence checkseapproval/bots.py— automation role dispatcheapproval/registry_view.py— state transition mapping
3.9 edges
Explicit DAG edges. If absent or empty, the DAG engine falls back to deriving edges from roles[].precondition_ids with trigger "assert".
[
{
"from_role_id": "550e8400-e29b-41d4-a716-446655440010",
"to_role_id": "550e8400-e29b-41d4-a716-446655440011",
"trigger": "assert"
}
]
| Field | Type | Description |
|---|---|---|
from_role_id | str (UUID) | Source role |
to_role_id | str (UUID) | Target role |
trigger | str | One of: assert, object_correctable, object_terminal, bot_failed |
Consumers:
eapproval/dag.py— primary edge sourceeapproval/gates.py— gate recomputation after claims
3.10 evaluation_criteria
Checklists attached to role + requirement pairs.
[
{
"id": "550e8400-e29b-41d4-a716-446655440020",
"role_id": "550e8400-e29b-41d4-a716-446655440010",
"requirement_id": "550e8400-e29b-41d4-a716-446655440002",
"checklist": [
{"item": "Name is not offensive", "required": true}
]
}
]
| Field | Type | Description |
|---|---|---|
id | str (UUID) | Criteria primary key |
role_id | str (UUID) | Owning role |
requirement_id | str (UUID) | Owning requirement |
checklist | array | null | JSON array of checklist items |
3.11 qualifications
What an applicant may qualify for, decided by their own answers (D58). A snapshot minted before
M101 carries filters instead; read paths accept both, and a legacy filter reads as a
qualification with no rule (it never applies, exactly as before, since nothing evaluated it).
| Field | Type | Description |
|---|---|---|
code | str | stable identity; fee lines and application stamps join on it |
name, labels | str, {locale: str} | the title the applicant sees |
explanation, explanations | str | null, {locale: str} | null | the one sentence the applicant reads |
rule | object | null | {"operator": "all"|"any", "children": [...]}; a leaf is a comparison, membership, pattern or temporal rule plus field |
summary | str | null | the plain sentence of the rule, written by the editor |
visibility | "applicant" | "agency" | agency-only qualifications never appear in public responses |
assigned_requirement_ids | array[str] | questions asked only when the qualification applies |
legal_basis | str | null | the act and section that create it |
legacy_condition | str | null | the sentence a converted filter or fee condition carried |
The OpenAPI document carries the applicant-visible ones as x-opengov-qualifications; a legacy
snapshot also keeps x-opengov-filters. POST /procedures/{id}/qualifications/evaluate with
{"answers": {...}} returns each visible qualification’s state (indicated, not_indicated,
undecidable, unreadable) and a reason that names a question, never an answer.
3.12 event_bindings
Snapshotted SmartLink event bindings at publish time. Changes to live EventBinding rows after publish do not affect already-published specs.
[
{
"id": "550e8400-e29b-41d4-a716-446655440040",
"name": "Notify LRA on registration",
"description": "Sends business data to LRA",
"trigger": "gate_passed",
"filter": {"role_id": "550e8400-e29b-41d4-a716-446655440010"},
"connector_code": "lra",
"operation_code": "register_business",
"operation_version_pin": null,
"payload_template": null,
"recipient_idempotency": "verified_by_probe",
"terminal_activation_ack": false,
"schema_hash": "a3f7c2..."
}
]
| Field | Type | Description |
|---|---|---|
id | str (UUID) | Binding primary key |
name | str | Human label |
description | str | null | Long-form description |
trigger | str | gate_passed, gate_failed, all_gates_passed, convergence_passed |
filter | object | Default {}; may contain role_id |
connector_code | str | SmartLink connector code |
operation_code | str | SmartLink operation code |
operation_version_pin | int | null | Optional version pin |
payload_template | str | null | JSONata template for request body |
recipient_idempotency | str | verified_by_probe, attested_by_admin, not_supported, unknown |
terminal_activation_ack | bool | Whether binding requires explicit activation ack |
schema_hash | str | SHA-256 of the operation’s request schema at publish time |
3.13 integration_standards_compliance
Aggregate summary of event bindings for compliance dashboards.
{
"bindings_count": 3,
"verified_by_probe_count": 2,
"attested_by_admin_count": 0,
"not_supported_count": 0,
"unknown_count": 1,
"external_bindings_count": 1,
"terminal_activation_ack_count": 0,
"last_probe_summary": {
"earliest_last_probe_at": "2026-04-01T12:00:00Z",
"latest_last_probe_at": "2026-04-05T12:00:00Z"
}
}
| Field | Type | Description |
|---|---|---|
bindings_count | int | Total bindings |
verified_by_probe_count | int | Bindings with recipient_idempotency == "verified_by_probe" |
attested_by_admin_count | int | Bindings with recipient_idempotency == "attested_by_admin" |
not_supported_count | int | Bindings with recipient_idempotency == "not_supported" |
unknown_count | int | Bindings with recipient_idempotency == "unknown" |
external_bindings_count | int | Bindings targeting external connectors |
terminal_activation_ack_count | int | Bindings with terminal_activation_ack == true |
last_probe_summary | object | null | {earliest_last_probe_at, latest_last_probe_at} or null |
4. Proof Modes
Proof modes live inside sections[].requirements[].formal_criteria as a free-form dict with a canonical shape.
4.1 Canonical structure
{
"modes_of_proof": [
{
"type": "agency_api",
"smartlink_binding": {
"connector_code": "lra",
"operation_code": "validate_tin"
},
"input_fields": ["tin"],
"required_inputs": ["tin"],
"lookup_mode": "display",
"lookup_label": "Validate TIN",
"debounce_ms": 500,
"response_to_form_mapping": {}
},
{
"type": "self_assertion"
}
],
"preferred_mode": "agency_api"
}
4.2 Valid type values
From src/opengov/smartrules/constants.py:
| Type | Meaning |
|---|---|
self_assertion | Applicant declares the value without evidence |
applicant_document | Uploaded document provided by applicant |
agency_document | Document held by the agency |
agency_api | Real-time API call to agency system (SmartLink) |
third_party_document | Document from an external party |
third_party_api | Real-time API call to third party (SmartLink) |
4.3 API proof mode extra fields
Only agency_api and third_party_api may carry:
| Field | Type | Description |
|---|---|---|
smartlink_binding | object | {connector_code, operation_code} |
input_fields | array[str] | Form field names to send in the request |
required_inputs | array[str] | Subset that must be non-empty before triggering |
lookup_mode | str | display (show result), fill (auto-fill form), validate (green/red) |
lookup_label | str | Button / link label |
debounce_ms | int | Delay before triggering lookup on typing |
response_to_form_mapping | object | Mapping of response keys → form field names (only for fill) |
5. field_capabilities
Injected at publish time if an API proof mode has a valid SmartLink binding and the operation exists.
{
"has_lookup": true,
"lookup_mode": "display",
"lookup_label": "Validate TIN",
"debounce_ms": 500,
"requires_auth": false,
"cache_scope": "shared",
"input_fields": ["tin"],
"required_inputs": ["tin"],
"response_to_form_mapping": {}
}
| Field | Type | Description |
|---|---|---|
has_lookup | bool | Always true if emitted |
lookup_mode | str | display, fill, validate |
lookup_label | str | Human label |
debounce_ms | int | Delay before trigger |
requires_auth | bool | Whether the operation requires authenticated callers |
cache_scope | str | shared, user, session |
input_fields | array[str] | Fields to send |
required_inputs | array[str] | Required fields before trigger |
response_to_form_mapping | object | Fill mapping (only when lookup_mode == "fill") |
Important:
field_capabilitiesis resolved at publish time against the current SmartLink operation config. If the operation is deleted or changed later, already-published specs retain the old capabilities.
6. Consumer Expectations
| Consumer | Reads from spec | Fallback if missing |
|---|---|---|
| Portal listing | procedure.name | "" |
| Portal form | sections[].requirements[] | Empty form |
| Portal lookup | sections[].requirements[].field_capabilities + formal_criteria.modes_of_proof[].smartlink_binding | HTTP 422 (lookup not configured) |
| eApproval DAG | roles[], edges[] | Derive edges from precondition_ids |
| eApproval gates | roles[].node_type, roles[].can_terminate | Defaults (verification, false) |
| eApproval claims | roles[].id | HTTP 400 (invalid role) |
| eApproval bots | sections[].requirements[].formal_criteria.modes_of_proof[] | manual_needed |
| eApproval registry view | requirements[].registry_column + state_transitions | Fallback to sections[].requirements[] |
| eApproval inbox | procedure.name | "(untitled)" |
| Published API | Full spec via FormSchemaV1 | Pydantic validation error at API boundary |
| Integration events | event_bindings[] | No events dispatched |
7. Backward Compatibility Rules
- New keys are additive. Never remove a key that existing consumers read.
- Consumers use
.get()with defaults. All runtime code is defensive. - Optional keys in
FormSchemaV1. The Pydantic model marks post-Plan-2 keys as| None = None. - Schema version is static.
schema_version: 1is hard-coded. There is no migration logic for spec contents. - Legacy specs without
requirementscontract block are handled byeapproval/registry_view.pyfalling back tosections[].requirements[]. - Legacy specs without
event_bindingssimply dispatch no integration events.
8. Versioning & Evolution
If a breaking change to the spec schema is ever needed:
- Bump
schema_versionto2insmartrules/publishing.py. - Add a new Pydantic model (e.g.
FormSchemaV2) inpublished/schemas.py. - Teach consumers to branch on
schema_version. - Update
tests/published/test_formschema_v1.pyto cover both versions.
Current policy: Avoid breaking changes. Add optional keys instead.
9. Minimal vs Maximal Example
Minimal spec (legacy, pre-Plan 2)
{
"schema_version": 1,
"procedure": {
"id": "uuid",
"name": "Simple Procedure",
"version": 1
},
"agency": {"id": "uuid"},
"total_requirements": 0,
"sections": [],
"roles": [],
"edges": [],
"evaluation_criteria": [],
"filters": []
}
Maximal spec (Phase 2B)
See tests/evals/_seeds/lesotho_business_permit/procedure.json for a real-world maximal example.
10. Further Reading
src/opengov/smartrules/publishing.py—publish_procedure()and spec constructionsrc/opengov/published/schemas.py—FormSchemaV1Pydantic modelsrc/opengov/eapproval/dag.py— DAG computation from specsrc/opengov/eapproval/gates.py— Gate initialization from specsrc/opengov/eapproval/registry_view.py— Contract-based registry viewtests/published/test_formschema_v1.py— Schema validation teststests/smartrules/test_publishing.py— Publish-time assertionsdocs/runbooks/module-interactions.md— How to read the spec viaSmartRulesService