pydantic-models

Designs and validates Pydantic v2 data models with aliases, validators, and discriminated unions.

Updated Sep 2, 2026
One-click install
npx skills add https://github.com/Dazlarus/karl-code --skill pydantic-models-dazlarus
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: pydantic-models
Source: https://github.com/Dazlarus/karl-code/tree/main/.agents/skills/pydantic-models
Command: npx skills add https://github.com/Dazlarus/karl-code --skill pydantic-models-dazlarus

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires pydantic.

What problem does it solve? Writing data validation logic by hand leads to brittle manual parsing, inconsistent type coercion, and missed edge cases when handling external API responses or user input. This Skill provides Pydantic v2 patterns that replace ad-hoc dict parsing with declarative, type-safe model validation. ## Core Features & Use Cases - Native v2 Validation: Uses model_validate, field_validator, and model_validator instead of manual parsing functions. - External Data Mapping: Handles mismatched field names with Field aliases and ORM objects with from_attributes. - Advanced Modeling: Covers nested models, discriminated unions for variant types, computed fields, strict mode, and serialization controls. - Use Case: When integrating a third-party REST API that returns camelCase JSON, define a Pydantic model with aliases and validators so responses are parsed, type-checked, and normalized in one model_validate call. ## Quick Start Review my Pydantic models in models.py and refactor any manual parsing into proper Pydantic v2 validation.

Frequently Asked Questions about pydantic-models

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I validate external API responses with Pydantic v2?▼

Define a BaseModel subclass with typed fields and call Model.model_validate(data) on the response payload. Use Field(alias="externalName") when the API uses different key names than your Python attributes.

How to map Pydantic fields to different JSON key names?▼

Use Field aliases, for example name: str = Field(alias="userName"), so model_validate accepts the external naming. For ORM objects, set model_config = {"from_attributes": True} and validate the object directly.

Does Pydantic v2 coerce string values to integers automatically?▼

Yes, by default Pydantic v2 coerces compatible types, so the string "123" becomes the integer 123. To reject implicit coercion, enable strict mode with model_config = ConfigDict(strict=True).

When should I use discriminated unions in Pydantic?▼

Use discriminated unions when a field can be one of several model variants distinguished by a literal tag field, such as a transport config with type "http" or "stdio". Annotate the union with Field(discriminator="type") so validation picks the correct variant.

When should I not use Pydantic models?▼

Avoid Pydantic when simple dataclasses without validation needs are sufficient or when working with non-structured data. The overhead of model definition and validation adds no value in those cases.