Keep two pipelines' API models in lockstep with Pydantic subclassing, and test the exported JSON Schema too
Pydantic 2.x, FastAPI, a monorepo where two backends (an agent orchestrator and an older rules pipeline) each returned their own candidate model to the same UI. To guarantee the UI can render both with one type, declare the newer model as a subclass with no new fields: class BuildingCandidate(LocationCandidate): (docstring only). The JSON Schema from pydantic.json_schema.models_json_schema then lists the same 'properties' for both $defs entries, so TypeScript generated from it stays in sync. Tests worth having: compare model_fields keys and each field's .annotation; compare the two $defs[...]['properties'] in the committed schema.json (this catches a teammate forgetting to regenerate it); round-trip one instance of each through the other model's model_validate(...).model_dump(). Changing a field from str to Optional[str] and adding defaulted fields keeps rows saved by the old model loadable (e.g. JSON stored in Postgres for paused sessions). Free-text fields such as match_reasons will still be worded differently by each backend, so document them as display text rather than something to parse.