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.
npx agentmods add rules/nedcodes-ok/cursorrules-collection/pydanticgit clone --depth 1 https://github.com/nedcodes-ok/cursorrules-collectionWrote 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.
[](https://agentmods.dev/rules/nedcodes-ok/cursorrules-collection/pydantic)<a href="https://agentmods.dev/rules/nedcodes-ok/cursorrules-collection/pydantic"><img src="https://agentmods.dev/badge/rules/nedcodes-ok/cursorrules-collection/pydantic.svg" alt="Measured on agentmods" height="20"></a>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.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.00479 | $0.00479 |
| Opus 5 | $0.00239 | $0.00239 |
| Sonnet 5 | $0.00096 | $0.00096 |
| Haiku 4.5 | $0.00048 | $0.00048 |
Grade A, and why
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 yesterday.
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.
How it starts
The opening of the file, as written. The whole thing — 47 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Pydantic Cursor Rules
You are an expert in Pydantic v2 data modeling. Follow these rules:
Models
- Inherit from BaseModel for all data classes — never use plain dataclasses for validated data
- Use model_config = ConfigDict(...) instead of inner class Config (v2 style)
- Set model_config = ConfigDict(strict=True) when you need strict type coercion
- Use frozen=True for immutable models — especially for value objects and configs
Fields
- Use Field() for metadata: Field(description="...", examples=[...], ge=0, max_length=100)
- Set Field(default=...) or Field(default_factory=list) — never use mutable defaults
- Use Annotated[int, Field(gt=0)] style for reusable constrained types
- Mark optional fields explicitly: name: str | None = None
Validators
- Use @field_validator("field_name") for single-field validation
- Use @model_validator(mode="before") for cross-field or raw-input transforms
- Use @model_validator(mode="after") for cross-field validation on parsed models
- Return the value from field validators — forgetting this silently sets None
- Use mode="wrap" validators only when you need to control the entire parsing pipeline
Serialization
- Use model_dump() and model_dump_json() — never dict() (deprecated)
- Use model_dump(exclude_none=True) to omit unset optional fields
- Use @field_serializer for custom output formatting (dates, enums, decimals)
- Use model_validate() and model_validate_json() for deserialization
Settings
- Use BaseSettings for environment/config with SettingsConfigDict(env_prefix="APP_")
- Layer sources: .env file → environment variables → constructor args
- Use @field_validator for settings that need post-load transformation
- Separate settings by concern: DatabaseSettings, AuthSettings, AppSettings
Patterns
- Use TypeAdapter for validating non-model types: lists, dicts, unions
- Use discriminated unions with Literal + Discriminator for polymorphic models
- Use computed_field for derived properties that should appear in serialization
- Define reusable types: PositiveInt = Annotated[int, Field(gt=0)]
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.
- yesterday First seen · 47 lines · 479 tokens per session scan A 306aa57191b0
pydantic is a cursor rule published in the GitHub repository nedcodes-ok/cursorrules-collection (37 stars, last pushed 6mo ago), licensed MIT. It adds 479 tokens to every session, about $0.0024 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-09-03.
Other cursor rules, from other repositories
cursorrules
You are building an AI/ML project with Python. The project uses PyTorch for model training, handles data pipelines with proper validation, tracks experiments systematically, and follows production ML engineering practices. Code is type-hinted, tested, and reproducible.
rule
AI/ML Python development (PyTorch, scikit-learn).
python
Python best practices.
pyspark-etl-best-practices-cursorrules-prompt-file
Cursor rules for PySpark ETL development with code style, joins, window functions, map operations, and Iceberg patterns.
python-llm-ml-workflow-cursorrules-prompt-file
Cursor rules for Python LLM & ML development with workflow integration.
automl-hyperparameter-optimization
AutoML and hyperparameter optimization rules for Python ML projects using Ray Tune, Optuna, PyCaret, and time-series AutoML libraries.