MARK GARASLEGAL AI & SOFTWARE

Legal ↔ Technical / Architecture map

Legal Labelling Engine

Compare two versions of a legal form, review the field mapping and test both the filled values and the rendered pages before export.

Workflow SVG ↓Project case study ↗

Current workflow review / 31 October 2026

A clean serial run passed all 158 engine tests on 31 October 2026, including the four previously intermittent paths. The synthetic demonstration rejects an incorrect mapping and an outdated approval, replays an accepted correction, and blocks a split field when a required fact is missing.

Read the updated case study ↗Current verification record ↓
The map below describes its original snapshot. The note above covers later fixes and checks; older results below still belong to the earlier version.

01 / Workflow

How the work moves through the system.

Read from left to right. Open a step to see why it matters, how it works, and where to find the code.

Process or decisionEvidence or data exchange

01Documents & context

implemented

Authorized forms and mapping

The maintainer provides old and new PDFs and a literal field mapping. The local adapter inventories fields and widgets and ties the review to the exact source files.

Legal ↔ Technical
Legal purpose

Preserve the record of what changed.

How it works

Bounded PDF subprocess inspection, SHA-256 identities and a restricted JSON or docassemble mapping adapter.

  • engine/cli.py:22prepare
  • engine/adapters/pdf.py:386inspect_pdf
  • engine/adapters/docassemble_map.py:377load_mapping
implemented

Independent expected results

The test author supplies expected values and reference PDFs independently of the candidate output. Their source hashes, origins and oracle revision are recorded.

Legal ↔ Technical
Legal purpose

The proposed mapping must not grade itself.

How it works

ReplayCase validation and counterfactual/value-domain coverage requirements.

  • engine/cases.py:19validate_case
  • engine/bundle.py:25_coverage

02Application & processing

implemented

Propose a field plan

The engine proposes the field relationships it supports and keeps unresolved changes visible. It also prepares a reversible mapping patch for review.

Legal ↔ Technical
Legal purpose

Distinguish a structural match from a legal judgment.

How it works

Deterministic relation proposals and MigrationPlan validation; missing required mappings block readiness.

  • engine/relations.py:136propose
  • engine/migration.py:103make_plan
implemented

Replay data and appearance

Replay checks filled values and rendered pages separately against the independent references. Incorrect or unsupported results cannot count as passing evidence.

Legal ↔ Technical
Legal purpose

Catch misplaced values and display failures before handoff.

How it works

Independent page-widget traversal plus PDFium rendering and bounded appearance comparison.

  • engine/replay.py:206replay
  • engine/replay.py:141widget_values
  • engine/proof.py:157render_compare

03Review & decisions

implemented

Correct or retire a binding

A reviewer can change a destination or retire an optional binding, with a recorded reason. The page downloads a request tied to the plan; the CLI uses it to create a fresh review workspace.

Legal ↔ Technical
Legal purpose

Record the person’s reason without silently removing a required obligation.

How it works

Offline selectors and revision JSON feed revise(); required bindings cannot retire and incompatible or colliding changes fail validation.

  • engine/report.py:16render_report
  • engine/cli.py:61revise
  • engine/migration.py:34_overrides
  • engine/migration.py:59_retirements
implemented

Accept the exact plan

The workflow owner accepts or rejects the exact plan hash after reviewing source locations and unresolved items. Export still requires the unresolved-item and evidence checks to pass.

Legal ↔ Technical
Legal purpose

Acceptance belongs to a person and is specific to the reviewed change.

How it works

Approval JSON binds plan_sha256; a revision changes that hash and invalidates the old approval.

  • engine/migration.py:319approve
  • engine/migration.py:330export_mapping

04Records & handoff

implemented

Export and repeat the checks

Approval, source links, coverage and a fresh replay must all pass before export. The bundle contains the new mapping, rollback files, scoped labels and a regression runner; the live interview stays unchanged.

Legal ↔ Technical
Legal purpose

Handoff stays reversible and its verification scope remains visible.

How it works

Bundle construction reruns checks; verify-bundle recomputes artifacts and the exported runner repeats replay.

  • engine/bundle.py:153export_bundle
  • engine/bundle.py:250verify_bundle
  • engine/migration.py:356reverse_mapping
Read the connections as a list
  • Authorized forms and mapping → Propose a field planInspect sources
  • Propose a field plan → Correct or retire a bindingReview proposed changes
  • Correct or retire a binding → Accept the exact planReview the fresh plan
  • Accept the exact plan → Replay data and appearanceContent-bound decision
  • Independent expected results ⇢ Replay data and appearanceIndependent oracle
  • Authorized forms and mapping ⇢ Replay data and appearanceExact template bytes
  • Replay data and appearance → Export and repeat the checksFresh passing evidence
  • Propose a field plan ⇢ Export and repeat the checksOriginal mapping for rollback

02 / Implementation traces

Follow an action into the code.

7 grouped traces. The model and retrieval entries show which integrations run, which use local rules, and which are only configured.

implemented

CLI inspect; --help and --version

Identify the supplied form before migration.

Interface / command
engine/cli.py:main
Call
legal-label inspect PDF [--output JSON]
Service / backend
engine/adapters/pdf.py:inspect_pdf
Rules & validation
Inventories canonical fields, physical widgets and diagnostics; unsupported input yields an explicit non-success status.
Model / provider
none
Prompt
none
Retrieval / sources
none
Persistence
Optional inventory JSON
Review & permissions
Local owner must have authority to inspect inputs.
Output
Source-bound inventory and parser findings.
  • engine/cli.py:255main
  • engine/adapters/pdf.py:386inspect_pdf
implemented

CLI propose; relation inventory, source links and patch in review.html

Inspect exactly which form bindings are retained, proposed or unresolved.

Interface / command
engine/cli.py:prepare; engine/report.py:render_report
Call
legal-label propose --old --new --mapping --output
Service / backend
engine/relations.py:propose; engine/migration.py:make_plan
Rules & validation
Loads literal mappings without executing expressions, derives structural relations, validates and writes a fresh workspace.
Model / provider
none
Prompt
none
Retrieval / sources
none
Persistence
old.pdf/new.pdf, inventories, mapping.json, plan.json, source-record.json, review.html
Review & permissions
Existing outputs cannot be overwritten; required unknowns block the plan.
Output
Immutable proposal workspace.
  • engine/cli.py:22prepare
  • engine/relations.py:136propose
  • engine/migration.py:103make_plan
  • engine/report.py:16render_report
implemented

Offline correction / retirement controls; CLI revise

Allow a maintainer to correct a one-to-one relation while recording rationale and retaining required bindings.

Interface / command
engine/report.py:render_report
Call
Local review-decisions.json download → legal-label revise DIRECTORY --decisions --output
Service / backend
engine/cli.py:revise; engine/migration.py:_overrides / _retirements
Rules & validation
The browser checks reasons and duplicate manual targets; the CLI rechecks base hash, sources, compatibility, collisions and required-binding retirement restrictions.
Model / provider
none
Prompt
none
Retrieval / sources
none
Persistence
A fresh review workspace and review-change.json; original workspace preserved.
Review & permissions
Reviewer name/role and rationale; acceptance disabled while local edits are pending.
Output
A new plan requiring its own approval and replay.
  • engine/report.py:16render_report
  • engine/cli.py:61revise
  • engine/migration.py:34_overrides
  • engine/migration.py:59_retirements
implemented

Offline acceptance/rejection; CLI approve

Record the workflow owner’s decision about one exact plan.

Interface / command
engine/report.py:render_report; engine/cli.py:main
Call
Local approval.json download or legal-label approve PLAN --reviewer --decision --output
Service / backend
engine/migration.py:approve; export_mapping
Rules & validation
Hashes the full plan content; export refuses rejection, a stale approval, source mismatch or unresolved required binding.
Model / provider
none
Prompt
none
Retrieval / sources
none
Persistence
approval.json
Review & permissions
Named local reviewer; no identity provider or digital signature.
Output
Content-bound acceptance or rejection record.
  • engine/report.py:16render_report
  • engine/migration.py:319approve
  • engine/migration.py:330export_mapping
implemented

CLI replay and Independent replay table

Check whether representative values reach intended places and remain visibly correct.

Interface / command
engine/cli.py:main; engine/report.py:render_report
Call
legal-label replay --plan --cases --old --new --output
Service / backend
engine/replay.py:replay; engine/proof.py:render_compare
Rules & validation
Checks source/case commitments, field coverage, independent expected values, widget values and the supported rendered appearance separately.
Model / provider
none
Prompt
none
Retrieval / sources
none
Persistence
results.json, candidate PDFs, rendered comparison artifacts
Review & permissions
Test author supplies independent expected references; unsupported checks do not pass.
Output
Separate logical, rendered and overall outcomes with evidence.
  • engine/replay.py:206replay
  • engine/cases.py:19validate_case
  • engine/proof.py:157render_compare
implemented

CLI bundle, verify-bundle and exported regressions.py

Provide a reversible, reviewable handoff that can be checked again.

Interface / command
engine/cli.py:main; engine/bundle.py:RUNNER
Call
legal-label bundle …; legal-label verify-bundle DIRECTORY; python regressions.py --output
Service / backend
engine/bundle.py:export_bundle / verify_bundle
Rules & validation
Recomputes the plan, acceptance binding, source identities, domain/counterfactual coverage, fresh replay, scoped labels and file manifest.
Model / provider
none
Prompt
none
Retrieval / sources
none
Persistence
Mapping before/after JSON, optional ordered YAML, reverse patch, labels, approval, portable cases and runner
Review & permissions
All verification gates pass; no automatic live interview modification.
Output
Verified-in-tested-scope bundle and exact original mapping for rollback.
  • engine/bundle.py:122RUNNER
  • engine/bundle.py:153export_bundle
  • engine/bundle.py:250verify_bundle
  • engine/migration.py:356reverse_mapping
implemented

CLI capture-correction, proof and demo

Turn an accepted oracle correction into a new regression and reproduce narrow synthetic controls.

Interface / command
engine/cli.py:main
Call
legal-label capture-correction …; legal-label proof --output; legal-label demo --output
Service / backend
engine/cases.py:capture_correction; engine/proof.py:run_proof; engine/cli.py:demo
Rules & validation
A correction keeps the predecessor hash and requires a new case id/oracle revision; demonstrations include wrong mappings, stale approval and missing split facts.
Model / provider
none
Prompt
none
Retrieval / sources
none
Persistence
New case JSON, synthetic proof/demo artifacts and summaries
Review & permissions
Synthetic reviewer records are explicitly simulated; they are not legal approval.
Output
Executable correction case and scoped synthetic test evidence.
  • engine/cases.py:57capture_correction
  • engine/proof.py:264run_proof
  • engine/cli.py:81demo
Which parts of the app are mapped

All ten top-level CLI commands, CLI help/version, the offline relation/approval view, the offline correction controls and the exported regression runner. Internal PDF worker commands are implementation details, not end-user surfaces.

14 mapped0 partial0 unmapped
  • inspectimplemented

    Field/widget inventory and diagnostics.

  • proposeimplemented

    Fresh source-bound review workspace.

  • reviseimplemented

    Plan-bound changes in a new workspace.

  • approveimplemented

    Content-bound accept/reject record.

  • replayimplemented

    Logical and rendered outcome evidence.

  • bundleimplemented

    Fresh verification and reversible export.

  • capture-correctionimplemented

    Accepted replacement oracle becomes a new case.

  • verify-bundleimplemented

    Recompute manifest and gate evidence.

  • proofimplemented

    Frozen synthetic corpus and controls.

  • demoimplemented

    Synthetic end-to-end migration and review example.

  • CLI help/versionimplemented

    Argparse metadata.

  • Offline relation and approval viewimplemented

    Escaped source locations, evidence tables, patch and decision downloads.

  • Offline correction controlsimplemented

    Destination corrections, reasons and optional retirements.

  • Exported regressions.pyimplemented

    Verify bundle, resolve portable cases and rerun replay.

03 / Review and permissions

What needs to happen before the next step?

implemented

Local processing

The runtime has no model or retrieval connection; review HTML uses a hash-bound script and a CSP with connect-src none.

Code references
  • engine/report.py:16render_report
  • engine/adapters/docassemble_map.py:377load_mapping
implemented

Bounded untrusted PDF work

PDF inspection, filling and rendering run in subprocesses with input, output, time, object, page and pixel limits. CPU/file/file-descriptor caps are applied; the tested platform cannot enforce the requested data-segment cap.

Code references
  • engine/adapters/pdf.py:29_limits
  • engine/adapters/pdf.py:49_worker
implemented

Fresh content and reversible output

Source hashes, full plan hash, independent case commitments and new-output-only writes prevent stale evidence from silently authorizing a changed mapping.

Code references
  • engine/core.py:52write_new
  • engine/migration.py:248validate_plan
  • engine/bundle.py:153export_bundle
implemented

Separate technical and legal scope

Labels describe relations verified within the included replay cases; retirement records an observed reviewer decision and does not verify legal removal.

Code references
  • engine/bundle.py:63_labels
  • engine/report.py:16render_report

04 / Completion work

What changed in this snapshot.

Implemented change

Reasoned mapping corrections in the offline review page.

Every mapped old field now has a destination selector and rationale field, including required bindings. The page blocks duplicate selected destinations and missing reasons, disables acceptance after edits, and downloads a plan-bound revision request. Applying it creates a fresh plan; old approval cannot authorize the changed plan.

The engine already accepted overrides through a hand-authored decisions file, but the review page only authored retirements; maintainers could inspect ambiguity without correcting it in the same review workflow.

Options considered
  • Add model-assisted split and merge suggestions.
  • Add an authenticated multi-user service.
  • Let the existing offline page author reasoned one-to-one mapping corrections.
Files changed
  • engine/report.py
  • tests/test_review_overrides.py
  • README.md

Validation

passedpython3 -m unittest discover -s tests -p test_review_overrides.py -v

3 tests exercised the emitted JavaScript using Node, downloaded requests, applied the CLI revision, and refused old approval, duplicate destinations and missing reasons.

passedpython3 -m unittest discover -s tests -v (baseline before this change)

155 tests passed in 555.491 seconds before the new review controls were added.

passedpython3 -m unittest discover -s tests -p 'test_review*.py' -v

9 current review tests passed, including the 3 new emitted-script/revision tests and all existing review/retirement tests.

passedpython3 -m compileall -q engine tests

Current Python sources compile.

failedpython3 -m unittest discover -s tests -v (full post-change rerun)

158 tests ran in 892.842 seconds: 154 passed, 1 failed and 3 errored. The relocated regression runner timed out after 60 seconds; reviewer-override bundle assembly and the CLI demo failed the independent-replay gate; a wrong-party-swap test could not find an expected PDF field (StopIteration). All 9 current review/control tests passed within this run. Causes beyond the explicit timeout were not isolated; no full current-suite pass or production release readiness is claimed.

passedPYTHONPATH=tests python3 -m unittest test_bundle.BundleTests.test_relocated_bundle_runs_without_original_reference_paths test_bundle.BundleTests.test_reviewer_override_binding_receives_verified_label test_replay.ReplayTests.test_wrong_party_swap_fails_despite_unchanged_field_count test_e2e.CliTests.test_demo_is_end_to_end_and_refuses_overwrite -v

The exact 4 previously failed/errored tests passed serially on the current source in 274.832 seconds. No source logic, assertions, timeouts or gates were changed. This limited rerun does not erase the earlier 154/158 full-suite result and is not a clean full-engine release run.

passedBounded source and report-purity diagnosis

Bundle replay refuses at engine/bundle.py:202 before report generation at :229; engine/replay.py and the PDF adapter do not import or call engine.report. Five renders of both current and preserved original report.py left synthetic plan/inventory hashes unchanged. An isolated comparison copy differs only in report.py; replay, PDF adapter, migration, proof and bundle source are identical. No new-control product defect was isolated; the earlier broad-run failure cause remains unproven.

Scope of the tool

  • Technical replay checks the supplied values and supported PDF appearance profile; it does not establish unchanged legal meaning or legal sufficiency.
  • No model, search service, cloud upload or interview-expression execution is connected.
  • Local approval binds content but does not authenticate the reviewer’s identity.
  • XFA, encrypted or signed forms, scans and unsupported appearance profiles remain blocked or unsupported.

Unfinished work and gaps in the map

  • No legal-semantic evaluator, live docassemble execution, lawyer usability study or production customer evidence.
  • No authenticated reviewer identity or multi-tenant service isolation.
  • XFA and secured historical forms have not cleared outcome replay gates.
  • Physical appearance coverage is deliberately narrow; an unsupported outcome remains blocked.
  • New controls have automated script/revision tests; graphical usability and keyboard testing remain future work.
  • Full post-change engine suite: 154/158 passed. The four failed/errored cases subsequently passed serially (4/4, 274.832 seconds) without changing gates or deadlines. The prior full-run failures remain recorded; a clean full-engine release run is pending and no production validation is claimed.
  • Professional acceptance and independent replay are still required after a correction.
  • The selector cannot provide missing facts for a split or merge.
  • The test JavaScript harness checks DOM control behavior; no full graphical browser usability study was run.
  • A clean full-engine release run remains pending. The earlier full run had four failures/errors; those exact four passed a later serial rerun without changes, but the earlier failure cause was not established.

Source references

docassemble: Assembling documents ↗ livingVerified 26 October 2026. Describes attachment templates and itemized PDF fields; the local adapter implements only its documented static mapping subset.

Implementation snapshot

These maps explain the software, its sources, and who reviews the results. Local and synthetic tests do not establish legal accuracy or readiness for production. The technical traces identify configured integrations and unfinished paths.