dto-factory-method

Convert inconsistent API responses into typed Pydantic domain models.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/dragonkid/dotfiles --skill dto-factory-method
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dto-factory-method
Source: https://github.com/dragonkid/dotfiles/tree/main/claude/skills/learned/dto-factory-method
Command: npx skills add https://github.com/dragonkid/dotfiles --skill dto-factory-method

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill translates messy external API responses into clean, typed domain models using Pydantic, applying a factory method to centralize conversion and provide consistent defaults.

Core Features & Use Cases

  • From API to domain: Convert varied API payloads to a unified domain model with a single factory method.
  • Default handling: Provide safe defaults for missing or optional fields to prevent runtime errors.
  • Output versatility: Support multiple outputs (e.g., structured prompts, JSON, and display-friendly strings) from a single model.
  • Decoupling: Keep API structure separate from domain logic to simplify maintenance and testing.

Quick Start

Define a Pydantic model and implement a from_api_response class method, then call it with your API payload to obtain a ready-to-use domain object.

Frequently Asked Questions about dto-factory-method

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

FAQPage Schema
How do I convert inconsistent API responses into Pydantic models?

You convert inconsistent API responses into Pydantic models by implementing a `from_api_response` factory method. This centralizes data mapping and applies safe defaults for missing or optional fields to prevent runtime errors.

What is the best way to handle non-standard API field names in Python?

The best way to handle non-standard API field names is using a factory method to decouple API structure from domain logic. This centralizes mapping logic, keeping external payload inconsistencies separate from your core application.

How do I provide default values for missing fields when mapping API payloads?

You provide default values for missing fields during API payload mapping by defining Pydantic models with default parameters. The factory method leverages these defaults to ensure safe domain object instantiation.

Can I generate multiple output formats from a single Pydantic domain model?

Yes, you can generate multiple output formats from a single Pydantic domain model. The pattern supports optional output helpers like `to_prompt_lines` to produce structured text, JSON, or display-friendly strings.

When should I use a factory method for API data mapping?

You should use a factory method for API data mapping when API field names are non-standard, nested, or optional. It centralizes conversion logic and ensures consistent defaults across multiple required output formats.