agentleFS
d3vzer0d3vzer0/agent-skills/skills/pydantic/SKILL.md

pydantic

Skill1 starsChanged 4 months agoMITView on GitHub

Use when designing, implementing, reviewing, or debugging Pydantic models, validators or serializers.

8 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

8 rules. 0 are common, 6 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 4 edited versions we read keep these.

  • 6

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill for Pydantic V2 data validation work in Python codebases.

    line 15
  2. Very specific:

    Treat this skill and its references as the primary offline guide.

    line 27
  3. Distinctive:

    Put validation and normalization on the Pydantic model that owns the data.

    line 29
  4. Distinctive:

    Prefer built-in Pydantic features over custom parsing, custom conversion, or hand-written schema logic.

    line 30
  5. Very specific:

    Verify behavior with both valid and invalid examples, including the exact ValidationError locations when validation rules matter.

    line 33
  6. Distinctive:

    Check the project's existing Pydantic style before adding new patterns.

    line 38
  7. Distinctive:

    Add or update tests that validate successful parsing, rejected inputs, default handling, aliases, strictness, and serialization where …

    line 40
  8. Distinctive:

    Run focused tests, and include a quick direct model instantiation check when a dedicated test suite is unavailable.

    line 41

“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Pydantic

Use this skill for Pydantic V2 data validation work in Python codebases.

When to Use

  • Creating or changing BaseModel, RootModel, Pydantic dataclass, or settings classes.
  • Adding field constraints, aliases, defaults, strictness, validators, serializers, or JSON Schema metadata.
  • Validating non-model types with TypeAdapter.
  • Debugging ValidationError, PydanticUserError, schema rebuild, forward reference, coercion, or serialization behavior.
  • Reviewing or migrating code that still uses Pydantic V1 APIs like dict(), json(), parse_obj(), @validator, @root_validator, or Config.

Operating Rules

  • Treat this skill and its references as the primary offline guide. If more detail is needed and internet access is available, use the public Pydantic documentation at https://docs.pydantic.dev/latest/.
  • Model data shape with type annotations first, then add Field, Annotated, validators, or config only where needed.
  • Put validation and normalization on the Pydantic model that owns the data. Use field validators for single-field logic and model validators for cross-field invariants.
  • Prefer built-in Pydantic features over custom parsing, custom conversion, or hand-written schema logic. Use the source links in each reference only for deeper edge cases.
  • Remember that Pydantic validation guarantees the output type and constraints, not that input data was already valid.
  • Be explicit about coercion. Pydantic is lax by default; use strict validation when accepting coercion would be unsafe.
  • Verify behavior with both valid and invalid examples, including the exact ValidationError locations when validation rules matter.

Workflow

  1. Identify the Pydantic version and the task category: model design, field constraints, validators, serialization, settings, TypeAdapter, JSON Schema, or migration.
  2. Check the project's existing Pydantic style before adding new patterns.
  3. Implement the smallest model or validation change that expresses the data contract.
  4. Add or update tests that validate successful parsing, rejected inputs, default handling, aliases, strictness, and serialization where applicable.
  5. Run focused tests, and include a quick direct model instantiation check when a dedicated test suite is unavailable.

Core References

TopicUse ForReference
Models and validationBaseModel, validation methods, extra data, forward refs, RootModelmodels-validation
Fields and aliasesField, defaults, Annotated, constraints, aliasesfields-aliases
Field typesStandard library, Pydantic, network, strict, constrained, encoded, and optional extra field typesfield-types
Validatorsfield_validator, model_validator, validation context, errorsvalidators
Config and strict modeConfigDict, global config, strict validationconfig-strict-mode
Serialization and JSON Schemamodel_dump, serializers, schema generationserialization-json-schema
TypeAdapter and settingsAd-hoc validation, settings managementtype-adapter-settings

Templates

TemplateUse For
model.py.mdStarting a Pydantic V2 BaseModel with config, constraints, validation, and dumps.
validators.py.mdCopyable field, model, ValidationInfo, and reusable Annotated validator patterns.
settings.py.mdStarting a pydantic-settings configuration model with secret-safe patterns.

Scripts

ScriptUse For
list_pydantic_fields.pyImporting a Pydantic V2 model and printing field annotations, aliases, defaults, and metadata.

Quick Patterns

from typing import Annotated

from pydantic import BaseModel, ConfigDict, Field, ValidationError, field_validator


class User(BaseModel):
    model_config = ConfigDict(extra='forbid')

    id: int
    email: Annotated[str, Field(min_length=3)]
    display_name: str = Field(default='Anonymous', validate_default=True)

    @field_validator('email', mode='after')
    @classmethod
    def require_at_sign(cls, value: str) -> str:
        if '@' not in value:
            raise ValueError('email must contain @')
        return value


try:
    user = User.model_validate({'id': '123', 'email': 'a@example.com'})
except ValidationError as exc:
    print(exc.errors())
else:
    print(user.model_dump())
from pydantic import TypeAdapter

ids_adapter = TypeAdapter(list[int])
ids = ids_adapter.validate_python(['1', 2, 3])
payload = ids_adapter.dump_json(ids)

Common Review Checks

  • Required fields have no defaults; optional-nullable fields use T | None and still need = None if they are not required.
  • Defaults that must be validated use Field(validate_default=True) or ConfigDict(validate_default=True).
  • Mutable defaults are intentional. Pydantic deep-copies unhashable defaults, but default_factory is clearer for generated values.
  • Cross-field validators account for field order when using ValidationInfo.data.
  • Aliases distinguish validation input names from serialization output names when they differ.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.