Skip to content

feat(schemas): inference→validation roundtrip check on the training corpus #497

Closed

Description

@Sinity

Problem

The schema package files (polylogue/schemas/providers/*/versions/*/elements/*.schema.json.gz) contain three families of inferred annotations:

  • x-polylogue-values — closed value sets observed in the training corpus.
  • x-polylogue-foreign-keys — relational links between paths.
  • x-polylogue-mutually-exclusive — field pairs that never co-occurred in the training corpus.

After the inference run produces these, nothing checks that the schemas the inference emits are actually consumable by the runtime parse/validate pipeline against the same corpus. The proof catalog's previous attempt at this (schema.mutual_exclusion.exclusive) was tautological — the runner read the same annotation the synthetic-payload generator already respected by construction (see #496).

The gap is not "validate inferred annotations against unseen data." That is a ground-truth question — for things like mutual-exclusion pairs that come out of "fields never co-occurred in N samples," there is no automated check that distinguishes real format invariants from sampling artifacts, and manual review is the appropriate tool. We are not trying to build that.

The gap is: when schema inference (Path A) produces an artifact, the runtime parse/validate pipeline (Path B) must consume it correctly against the corpus Path A was given. The two paths today are independent code:

  • Path A — polylogue/schemas/generation_*.py and relational_inference_*.py, semantic_inference_*.py — produces annotations from samples.
  • Path B — polylogue/sources/parsers/*.py plus polylogue/schemas/audit_*.py — reads the committed schema artifact and validates incoming records during parse.

If Path A says "this enum is closed at {x, y, z}" and Path B then rejects a record from the same corpus (or accepts a value not in the enum without warning), the two paths have drifted. Today nothing flags that.

Target

Add a roundtrip consistency check tying inference to runtime validation.

Mechanism

devtools verify-schema-roundtrip (or extend schema-audit):

  1. For each provider/version, locate the corpus the schema was inferred from. The package's package.json records sample_count, first_seen, last_seen. The corpus itself lives in the live archive (raw_conversations filtered by provider + acquisition window) or under polylogue/schemas/synthetic/ for committed reference samples.

  2. Run each record through the actual parser (polylogue/sources/parsers/<provider>.py) and apply schema validation (schemas/audit_*.py or whatever the runtime uses) against the committed schema package.

  3. Expect zero validation failures and zero parser quarantines.

  4. On any failure, the report names the schema annotation, the offending record (raw ID), and which path emitted the disagreement.

Output

$ devtools verify-schema-roundtrip --provider chatgpt
chatgpt v1: validating 2122 training records against committed schema...
  parse: 2122/2122 ok
  schema validation: 2122/2122 ok
  inferred-annotation conformance:
    x-polylogue-values:           88 entries, 0 violations
    x-polylogue-foreign-keys:      7 entries, 0 violations
    x-polylogue-mutually-exclusive: 6065 entries, 0 violations
ok

A non-zero violation count is a real bug — the inference path emitted something the validation path can't accept against the data inference saw.

What this does and does not check

Detects:

  • Inference→validation grammar drift (inference emits a regex, validator parses it differently).
  • Schema serialization bugs (compress/decompress round-trip loses precision).
  • Annotation forms that the validator silently ignores.
  • Inference algorithm bugs that produce annotations the validator can't represent.

Does not detect:

  • Whether an inferred annotation reflects a real format invariant (the mutex sampling-artifact question — needs manual review).
  • Drift between inference time and future corpus shape (would need separately-stored holdout, which is not what this issue is).

Wired into proof catalog

A new claim:

  • claim: schema.inference_validation_roundtrip — "schema inference produces artifacts the runtime validator accepts on the corpus that produced them."
  • subjects: each provider/version pair.
  • runner: schema-roundtrip-validator.
  • evidence class: empirical (reads independently from the inference path).

This claim is not tautological in the way schema.mutual_exclusion.exclusive was: the synthetic-payload generator is not in the loop. The check uses the actual parse/validate pipeline against the actual training corpus.

Why this matters

  • Closes a real consistency gap. Today schema-audit checks internal properties of the schema artifact (privacy, role coverage); pipeline-probe runs the pipeline; nothing connects "the corpus the schema was inferred from" to "the schema the runtime uses to validate that corpus." The two-path divergence is a silent failure today.
  • Justifies keeping inferred annotations after fix(proof): drop x-polylogue-mutually-exclusive from catalog subjects #496. fix(proof): drop x-polylogue-mutually-exclusive from catalog subjects #496 drops mutex annotations from the proof catalog because the proof was tautological. This issue gives all three annotation families a real verification path that isn't a closed loop with the generator.
  • Honest scope. This is consistency, not correctness. Correctness of inferred invariants against future data is a ground-truth manual-review concern, not something this lint claims.

Acceptance (executable)

devtools verify-schema-roundtrip --provider chatgpt
devtools verify-schema-roundtrip --all      # exits 0 on clean roundtrip
devtools verify-schema-roundtrip --all --json

Wired into verify --quick as soft mode initially (per the soft-mode escalation manifest, #490), escalating to blocking once the existing schema set is known clean.

Coordination

Cross-reference: holistic assurance umbrella

Filed 2026-04-27. This issue is part of the holistic assurance coverage map (#506) which restructures verifiability work around four tracks (stop lying / coverage map / routing-proof-pack / product confidence) and introduces an Oracle primitive (#507), declarative coverage manifests (#508 assurance-domains, #509 oracle-quality), and operator-facing proof packs (#510).

Read in conjunction with #506 to see how this issue fits into the broader confidence model.

Activity

  1. added
    type:feat
    theme:verifiability
    on Apr 26, 2026
  2. changed the title [-]feat(schemas): held-out validation for inferred annotations[/-] [+]feat(schemas): inference→validation roundtrip check on the training corpus[/+] on Apr 26, 2026
  3. added a commit that references this issue on May 7, 2026
    dce5866
  4. Sinity commented on May 7, 2026

    @Sinity
    OwnerAuthor

    Closed-scope audit found the schema roundtrip command exists and passes, but the implemented proof appears narrower than the original issue wording; leaving this issue closed and tracking classification in #944.

    Evidence: devtools verify-schema-roundtrip --all --json passes for committed package manifests/elements and synthetic records derived from committed schemas. I did not find the original training-corpus/runtime roundtrip path that proves the schemas against the corpus used to infer them.

    #944 should decide explicitly whether that narrower package/synthetic check is the intended contract or add the missing corpus/runtime verification.

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

    area:schematheme:verifiabilitytype:feat

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions