PY-PYDA0004 · redundant_model_validate
Find model_validate calls that already spell out ordinary constructor fields.
This is a deterministic rule for python. Read its implementation.
Definition
Section titled “Definition”Report Model.model_validate only when its sole argument is a dictionary literal or a
keyword-only dict call with nonempty identifier keys and no validation options. In this
shape the code already knows every field and Model(field=value) states that intent more
directly. Keep model_validate at boundaries that receive an existing mapping, decoded
document, ORM object, plugin payload, or caller-selected validation options.
Evidence
Section titled “Evidence”Each finding identifies the call and every explicit input key. The rule does not infer model
schemas, aliases, or data produced at runtime. The value is the number of model_validate
calls carrying one literal mapping.
Exceptions
Section titled “Exceptions”Mapping variables, dictionary unpacking, non-identifier aliases, from_attributes, strictness,
context, and other validation options are excluded. Tests are excluded because literal
mappings there often exercise decoded configuration and invalid input boundaries. A thin
from_table method may reasonably call cls.model_validate(table) because the mapping itself
is the boundary.
Examples
Section titled “Examples”Bad
`User.model_validate({"name": name, "age": age})` repeats an ordinary constructor shape.
GoodUser(name=name, age=age) constructs explicit application values. User.model_validate(row)
validates an existing external mapping and remains appropriate.
References
Section titled “References”- Cites “Pydantic documentation”, models and model validation methods. Open reference
- Cites “Pydantic documentation”, aliases and mapping validation. Open reference