Skip to content

[validation] Close generated Pydantic vs canonical JSON Schema semantic gaps #1102

Description

@bokelley

Summary

Generated Pydantic models do not enforce all semantics in the canonical JSON Schemas. In particular, allOf + if/then/else conditionals and x-adcp-validation invariants can silently disappear from runtime model validation.

Reproduction from reporting

The reporting revision schema requires finality_basis, finality_policy_id, and finalized_at when finality == "official", and forbids that evidence for non-official revisions. The generated ReportingRevision Pydantic model accepted an official revision without those fields.

The same implementation also had to enforce canonical media-buy set ordering manually because that behavioral invariant is not represented by the generated model.

Impact

An adopter can construct or accept a Python object that appears validated but is rejected by the canonical protocol schema. For billing/reporting this can turn an unsupported finality assertion into apparently valid application state.

Decision needed

Choose and document one supported boundary:

  1. generated Pydantic models have validation parity with canonical JSON Schema, including conditionals and selected x-adcp-validation rules; or
  2. Pydantic models are structural application types only, and every wire boundary runs a provided canonical-schema validator in addition.

Expected work

  • Add differential fixtures that validate the same payload with Pydantic and the bundled canonical JSON Schema.
  • Cover conditional required/forbidden fields, discriminated unions, dependent constraints, numeric/string/array bounds, and selected behavioral extensions.
  • Fail SDK CI when a generated model accepts a canonical negative fixture unless the divergence is explicitly allowlisted and documented.
  • Provide an ergonomic validation helper if full codegen parity is not practical.

Discovered while implementing #1095 against adcontextprotocol/adcp#6953.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions