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

Written for no agent in particular: nothing here depends on one.

Good fit Use it to define records, validate input, create immutable value objects, serialize data, and move between dataclasses and Pydantic models.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/vikasudasi/skill-vault/python-dataclasses-pydantic
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.

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/github.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/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for python-dataclasses-pydantic

Your own site · 80×15
<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="Reviewed on agentmods" width="80" 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. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00033 $0.01634
Opus 5.5 $0.00013 $0.00654
Sonnet 5.5 $0.00007 $0.00327
Haiku 4.5 $0.00003 $0.00163

Measured 1mo ago against content hash f43f9aa9b470, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, 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 1mo 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. 1mo 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 2mo ago), licensed Apache-2.0. It adds 33 tokens to every session and 1,634 once invoked, about $0.0001 per session on Opus 5.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

migrating-langchain-to-pydantic-ai

Migrate Python LangChain, LangGraph, or Deep Agents applications to Pydantic AI and, when the source uses harness features, Pydantic AI Harness. Use for LangChain agents, chains, LCEL, direct LangGraph graphs, persistence, interrupts, streaming, and createdeepagent projects with planning, filesystem or sandbox…

pydantic/pydantic-ai · 100 tokens

migrating-mastra-to-pydantic-ai

Migrate TypeScript Mastra applications to Python with Pydantic AI and, only when needed, Pydantic AI Harness. Use when source code imports @mastra/ or relies on Mastra agents, tools, workflows, memory, processors, streaming, approvals, skills, or subagents.

pydantic/pydantic-ai · 73 tokens

migrating-vercel-ai-sdk-and-eve-to-pydantic-ai

Migrate TypeScript Vercel AI SDK or Eve applications to Python with Pydantic AI and, only when needed, Pydantic AI Harness. Use when source code imports ai, @ai-sdk/, or eve, or relies on generateText, streamText, ToolLoopAgent, useChat, Eve agents, tools, skills, subagents, approvals, sessions, channels, schedules…

pydantic/pydantic-ai · 107 tokens

migrating-pi-to-pydantic-ai

Migrate TypeScript Pi coding-agent applications, extensions, or packages to Python with Pydantic AI and Pydantic AI Harness. Use when source code imports @earendil-works/pi-, calls createAgentSession, registers Pi extensions, or relies on Pi tools, hooks, skills, sessions, compaction, providers, TUI, RPC, or packages.

pydantic/pydantic-ai · 88 tokens

migrating-claude-agent-sdk-to-pydantic-ai

Migrate Python applications from the Claude Agent SDK to Pydantic AI and, only when needed, Pydantic AI Harness. Use when source code imports claudeagentsdk or relies on Claude Code's agent loop, sessions, built-in tools, hooks, permissions, skills, or subagents. Do not use for the Anthropic Messages SDK or Claude…

pydantic/pydantic-ai · 90 tokens

migrating-google-adk-to-pydantic-ai

Migrate Python Google Agent Development Kit (ADK) applications to Pydantic AI. Use for LlmAgent, Runner, sessions, state, memory, tools, callbacks, plugins, graph or dynamic workflows, resumability, events, artifacts, MCP, and ADK deployment boundaries.

pydantic/pydantic-ai · 72 tokens