no-generic-json-parser
Parse consumed JSON fields with a bespoke declarative model instead of an open JSON parser.
Why
An open JSON domain validates syntax and value kinds without declaring required fields or their relationships; consumers must then reconstruct the contract manually.
Fix
Declare only the fields the consumer needs in a named Pydantic model and use model_validate_json or model_validate. Allow unrelated fields when the wire contract permits them. Document an exact-code exception for genuinely schema-agnostic infrastructure.
Examples
from pydantic import JsonValue, RootModel
class Response(RootModel[dict[str, JsonValue]]): passfrom pydantic import BaseModel
class Response(BaseModel): version: int