python-dataclasses-pydantic

python-dataclasses-pydantic is a skill for Claude Code, Codex from vikasudasi/skill-vault. It costs 33 tokens per session (1,634 once invoked), scanned A, original, Apache-2.0.

A guide to representing structured Python data with dataclasses and Pydantic. Dataclasses provide lightweight typed records, while Pydantic checks values at runtime and converts data such as JSON.

In plain words
What is it for?
Use it to define records, validate input, create immutable value objects, serialize data, and move between dataclasses and Pydantic models.
Why use it?
It makes data rules explicit and catches invalid records at the boundaries of an application instead of allowing bad values to spread.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/vikasudasi/skill-vault/python-dataclasses-pydantic
Any agent
npx skills add vikasudasi/skill-vault --skill python-dataclasses-pydantic
Clone the repo
git clone --depth 1 https://github.com/vikasudasi/skill-vault

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for python-dataclasses-pydantic

README.md
[![agentmods](https://agentmods.dev/badge/skills/vikasudasi/skill-vault/python-dataclasses-pydantic.svg)](https://agentmods.dev/skills/vikasudasi/skill-vault/python-dataclasses-pydantic)
Your own site
<a href="https://agentmods.dev/skills/vikasudasi/skill-vault/python-dataclasses-pydantic"><img src="https://agentmods.dev/badge/skills/vikasudasi/skill-vault/python-dataclasses-pydantic.svg" alt="Measured on agentmods" height="20"></a>
Per session 33 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,634 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00033 $0.01634
Opus 5 $0.00016 $0.00817
Sonnet 5 $0.00007 $0.00327
Haiku 4.5 $0.00003 $0.00163

Measured 2d ago against content hash f43f9aa9b470, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

python-dataclasses-pydantic scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

The scan reads SKILL.md. This mod also ships 1 executable file (scripts/model_example.py), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skill_vault/data/skills/python-dataclasses-pydantic/SKILL.md · 159 lines

How it starts

The opening of the file, as written. The whole thing — 159 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Data Modeling with Dataclasses + Pydantic

Use when a module carries structured records and you want type safety, validation, or clean JSON round-tripping. The two tools overlap but solve different problems: dataclasses are a lightweight typing/memory tool; Pydantic adds runtime validation + serialization at the boundary.

Type-safety with dataclasses

from __future__ import annotations
from dataclasses import dataclass


@dataclass(slots=True)
class Point:
    x: float
    y: float

@dataclass(slots=True) reduces memory and prevents accidental attribute typos (an unknown attribute becomes an AttributeError, not a silent new field).

Validation + serialization with Pydantic (v2)

from pydantic import BaseModel, Field


class SkillInput(BaseModel):
    name: str = Field(min_length=3, max_length=64)
    description: str
    tags: list[str] = Field(default_factory=list)
    port: int = Field(ge=1, le=65535)

    @field_validator("name")
    @classmethod
    def _no_whitespace(cls, v: str) -> str:
        v = v.strip()
        if not v:
            raise ValueError("name must not be blank")
        return v

Pydantic v2 is the current API (pydantic ≥ 2.0). Key calls:

  • Model.model_validate(data) — validate/coerce a dict or object.
  • Model.model_validate_json(s) — parse + validate a JSON string directly.
  • model.model_dump() / model.model_dump_json() — serialize to dict / JSON.
  • Field(...) — constraints and defaults (min_length, ge, default_factory).
  • @field_validator("x") — per-field post-validation transforms/checks.
  • @computed_field — a read-only property exposed in model_dump().
  • ConfigDict / model_config — e.g. model_config = ConfigDict(frozen=True, extra="forbid").

Nesting composes cleanly: a field whose type is another BaseModel is validated recursively, so you get a typed, validated object graph from JSON in one call.

Decision table: dataclass vs Pydantic

Concern @dataclass Pydantic BaseModel
Runtime validation / coercion of inputs ✗ none ✓ automatic, per-field
JSON round-trip manual asdict/json.dumps model_dump_json() / model_validate_json
Performance (creation in hot loops) fast, near-plain-class slower — validation overhead per instantiation
Mutable default lists/dicts foot-gun (see Pitfalls) default_factory handled, but Field(default_factory=...) still required
Immutable value objects frozen=True ConfigDict(frozen=True)
Serialization shape control manual rich (by_alias, exclude_unset, computed_field)
Syntax/deps stdlib, zero deps third-party dependency

Read the full file on GitHub · 159 lines

Files

What ships with it

2 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 159 lines · 33 tokens per session scan A f43f9aa9b470

Subscribe to this mod's changes

python-dataclasses-pydantic is a skill published in the GitHub repository vikasudasi/skill-vault (0 stars, last pushed 17d ago), licensed Apache-2.0. It adds 33 tokens to every session and 1,634 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

add-new-model

Add support for a newly-released LLM model in pydantic-ai (e.g. openai:gpt-5.6, anthropic:claude-sonnet-5). Use when a provider ships a new model id and you need to wire literals, profile flags, and tests to recognize it. Handles SDK-lag, gateway list conventions, and capability probing.

pydantic/pydantic-ai · 80 tokens

building-pydantic-ai-agents

Build AI agents with Pydantic AI — tools, capabilities (including on-demand loading), structured output, streaming, testing, and multi-agent patterns. Use when the user mentions Pydantic AI, imports pydanticai, or asks to build an AI agent, add tools/capabilities, defer capability loading, stream output, define agents…

pydantic/pydantic-ai · 85 tokens

migrating-langchain-to-pydantic-ai

Migrate Python LangChain or LangGraph applications to Pydantic AI. Use for LangChain agents, chains, LCEL, or direct LangGraph graphs, persistence, interrupts, and streaming. Do not use for migrations centered on createdeepagent or Deep Agents harness features.

pydantic/pydantic-ai · 69 tokens

datamodel-code-generator

Use this skill when the user wants Python data models, Pydantic models, dataclasses, TypedDicts, msgspec structs, or type-safe Python classes generated from OpenAPI, AsyncAPI, JSON Schema, GraphQL, JSON/YAML/CSV sample data, MCP tool schemas, Protocol Buffers, XML Schema, Apache Avro, or existing Python model objects.…

koxudaxi/datamodel-code-generator · 147 tokens

test-generator

Generate pytest test cases for Python functions and classes.

vstorm-co/pydantic-deepagents · 12 tokens

pydantic-ai-agents

Build and debug Pydantic AI v2 agents using best practices for dependencies, instructions, tools, capabilities, hooks, and structured output validation. Use when the user wants to: (1) Create a new Pydantic AI agent, (2) Debug or fix an existing agent, (3) Add features like tools, validators, capabilities, hooks, or…

Fuenfgeld/pydantic-ai-skills · 135 tokens