Skip to content

Validate a fragment on its own: tell "not declared here" from "malformed" #39

Description

@dvejsada

Summary

Clause libraries, and include fragments (§12.2), hold text meant to be inserted into another document. Validating one on its own draws errors that only the host document can resolve: ref-broken, term-undefined, party-unknown, side-unknown, attach-undeclared, and condition-invalid/choose-invalid for an undeclared question. The same rule ids also report mistakes inside the fragment itself that no host can fix:

  • a malformed when= (when=Audit_Rights, when=audit:);
  • a {{choose:}} in a heading;
  • a {{ref:}} whose target is not an identifier ({{ref: Bad Ref}}).

A Diagnostic carries only rule, level and message, so a caller can't separate the two cases without re-parsing the directive or matching message text. ForLegalAI/PactTrack does this in app/services/clause_analysis.py, re-lexing to decide which diagnostics a host could resolve.

Proposal

Either of these would work:

  1. Separate rule ids for "the target is not declared in this document", as opposed to "the directive or condition is malformed". For example, split condition-invalid into syntax and undeclared-question variants. The split for refs already exists in spirit: anchor-format and placeholder-id-malformed cover some of the malformed cases.
  2. A fragment mode: validate_document(document, *, fragment=True) reports cross-references to undeclared targets as a separate category, or with a host_dependent: bool on Diagnostic, and skips the frontmatter-level rules (sides-absent, parties-minimum, def-unreferenced) that don't apply to a fragment.

Related: #26, #35 (Full fragment checks with a loader).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions