Pydantic 2.14
Last reviewed Oct 25, 2026
Prompt Details
Prompt Composition
2prompts
- Python 3155 lines · 3.8K tokens
- Pydantic 2.1459 lines · 2.7K tokens
Total214 lines · 6.5K tokens
CWE Coverage
- 20
- 23
- 36
- 59
- 73
- 78
- 89
- 93
- 95
- 117
- 201
- 208
- 209
- 214
- 250
- 295
- 319
- 328
- 338
- 347
- 367
- 379
- 409
- 416
- 426
- 427
- 470
- 502
- 532
- 611
- 674
- 732
- 770
- 772
- 776
- 807
- 829
- 915
- 916
- 918
- 1104
- 1284
- 1287
- 1333
- 1395
Prompt Preview
Apply these rules to Pydantic 2.14 validation and serialization with the included Python baseline. This prompt covers Pydantic models and type adapters. Pydantic Settings and Pydantic AI are separate packages; settings-source precedence, dotenv handling, and settings secrets need their own review and are not covered here.
Input contracts
- Validate external values with
BaseModel.model_validate(),model_validate_json(), orTypeAdapter.validate_python()/validate_json()before using them. JSON Schema generation and Python annotations alone do not validate incoming data. - Define separate input and response models. Keep server-owned roles, tenant IDs, ownership, and approval state out of writable input fields; authorize the validated identifiers before acting on them.
extra='forbid'cannot protect privileged fields you explicitly declare. - Set
ConfigDict(extra='forbid')on boundary models and their nested model types; the default ignores unknown fields. Review per-callextraoverrides. If extension fields are required, type and constrain__pydantic_extra__and keep them out of privileged updates. - Configure
TypedDictand stdlib dataclass inputs withwith_configor__pydantic_config__, and Pydantic dataclasses withconfig=; they also ignore unknown keys by default. - On 2.14.0, which predates the 2.14.1 fix, a
TypedDictdoes not takeclosedorextra_itemsfrom a base class, so declare them on each validated class. - Use
ConfigDict(strict=True),Field(strict=True), or strict types when coercion could change a security decision. Review