What this thread does
Do first: use python -m pip show pydantic to identify the installed major, then record valid inputs, invalid inputs and exact public JSON before changing validators.
Short answer
As of November 2026, target Pydantic 2.14.4, released November 19 (checked 2026-11-24). The final V1 release, 1.10.27, ends V1 support, including the compatibility namespace; treat compatibility imports as temporary migration aids. Choose validation modes by input stage and serialization modes by output contract. A decorator rename alone cannot preserve default validation, error behavior or JSON shape.
Choose / don't choose
- Field validator: choose checks/transforms of one parsed field; use
mode="before"only when raw input transformation must precede parsing (validators). - Model validator: choose
mode="after"for cross-field invariants on parsed values; choose"before"for raw object/dictionary preprocessing,"wrap"when explicitly controlling validation around the handler. - Serializer: choose a field serializer for one field, model serializer for the whole envelope, or an Annotated serializer for a reusable type. Don't run formatting logic as validation solely to alter JSON (serialization).
Not for: regex engine compatibility; see pydantic-regex-is-removed-pattern-rust-python-engine.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
validate_default | True in Field(...) when defaults must undergo validation; model default False | Pydantic current docs, November 2026 | config, fields |
from_attributes | from_attributes=True in the model config for attribute-backed input, replacing the old ORM setting | Pydantic current docs, November 2026 | migration |
field_validator(mode=...) | "after" default for parsed values; "before" for raw inputs; always return the accepted value | Pydantic current docs, November 2026 | validators |
model_validator(mode=...) | "after" returns self after all fields; "before" receives raw input; "wrap" surrounds the handler | Pydantic current docs, November 2026 | validators |
field_serializer(when_used=...) | Accepts a string with values 'always', 'unless-none', 'json', and 'json-unless-none'. Defaults to ‘always’. | Pydantic current docs, November 2026 | serializer API |
field_serializer(mode=...) | "plain" default replaces normal serialization; "wrap" may call the standard handler | Pydantic current docs, November 2026 | serializer API |
Order of operations
1. Lock the target release and import models from the intended major. Replace inner legacy Config with model_config; convert ORM attribute access to from_attributes=True and model_validate (migration). 2. Move pre-parsing rules to before validators, then field parsing/checks, then cross-field after validation. Before validators must accept arbitrary raw input, including objects when attribute extraction is enabled. Return the instance from after model validators. 3. Use validate_default=True only where omission must trigger validation; compare omission, explicit null and invalid defaults. A nullable annotation without a default still requires the field (fields). 4. Replace JSON-only encoders with explicit serializers. For a field amount, choose @field_serializer("amount", when_used="json") and return the exact old public representation. Compare model_dump(), model_dump(mode="json") and model_dump_json(), including null, aliases, omitted fields and nested models (serialization, serializer API). 5. Assert public error codes and field paths as well as output. Keep implementation TypeError distinct from input ValidationError; compare subclass output deliberately because typed nested serialization can omit subclass-only fields (migration).
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
TypeError escapes a validator | It is no longer wrapped as ValidationError | Fix wrong signatures/type misuse as programmer errors; use ValueError or PydanticCustomError for intended input rejection. Keep unexpected TypeError on the server-error path | migration, validator errors |
cannot import name 'field_validator' | The report shows an ImportError for field_validator | Inspect the interpreter's installed distribution; resolve dependencies to the target major before changing decorator imports | dated discussion 9598 |
| Defaults skip custom checks (symptom) | Default validation disabled | Enable field/model validate_default=True and include omitted-input cases | fields |
Diagnostic: TypeError
Do not blanket-convert every TypeError into a client validation response: that can expose internal programming mistakes as bad user input. Source
Missing
- The original validators and output contract are unspecified; no generic serializer guarantees byte-for-byte compatibility.
- The general version policy still describes V1 fixes until the next major; the final V1 release above explicitly ends support. Use the newer release statement for that boundary.
Checked
2026-11-12; target/final-V1 releases, migration/configuration/fields/validators/serialization references, version policy and dated import-error discussion read. No migration or application commands executed.
Started from a post by @Pydantic, packaged by the editor. Original post