agentleFS
karim-bhalwanikarim-bhalwani/agent-skills-collection/skills/json-to-pydantic/SKILL.md

json-to-pydantic

Skill0 starsChanged 10 months agoMITView on GitHub

Convert JSON data snippets into Python Pydantic data models with proper type annotations and validation. Use when converting JSON schemas to Pydantic models, generating data validation models from JSON examples, or creating Python data classes.

1 other project uses a version of this, 1 of them edited.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

9 rules. About 0 are common, 4 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Analyze the Input: Look at the JSON object provided by the user.

    line 18
  2. Very specific:

    Use PascalCase for class names.

    line 35
  3. Very specific:

    Use type hints (List, Optional) from typing module.

    line 36
  4. Very specific:

    If a field can be missing or null, default it to None.

    line 37
  5. Distinctive:

    Must handle nested objects and optional fields correctly.

    line 50
  6. Distinctive:

    Ignoring Nested Structures: Not extracting nested objects into separate classes creates monolithic models.

    line 54
  7. Very specific:

    Skipping Validation: Not adding constraints like Field(min_length=1) or regex patterns.

    line 57
  8. Very specific:

    Mixing Array Element Types: Not using Union types when arrays can contain multiple types.

    line 58
  9. Distinctive:

    Missing Aliases: Not mapping JSON camelCase to Python snake_case with Field aliases.

    line 59

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

JSON to Pydantic Skill

This skill helps convert raw JSON data or API responses into structured, strongly-typed Python classes using Pydantic.

Instructions

  1. Analyze the Input: Look at the JSON object provided by the user.
  2. Infer Types:
    • string -> str
    • number -> int or float
    • boolean -> bool
    • array -> List[Type]
    • null -> Optional[Type]
    • Nested Objects -> Create a separate sub-class.
  3. Follow the Example: Review examples/ to see how to structure the output code. notice how nested dictionaries like preferences are extracted into their own class.

    • Input: examples/input_data.json
    • Output: examples/output_model.py

Style Guidelines

  • Use PascalCase for class names.
  • Use type hints (List, Optional) from typing module.
  • If a field can be missing or null, default it to None.

Outputs & Deliverables

  • Primary Output: Python Pydantic models with complete type annotations
  • Secondary Output: Validation rules and field defaults
  • Success Criteria: Models match JSON structure and include proper type hints
  • Quality Gate: Ready for integration into implementer's codebase

Constraints

  • NO business logic. Data models only.
  • NO implementation code beyond model definitions.
  • Must handle nested objects and optional fields correctly.

Common Pitfalls

  • Ignoring Nested Structures: Not extracting nested objects into separate classes creates monolithic models. Always decompose; create sub-classes for nested dicts.
  • Wrong Type Inference: Confusing null with missing fields. null = Optional, missing entirely = Field with default_factory. Be precise.
  • Generic Field Names: Using data, value, result instead of domain-specific names. Use the field name from JSON.
  • Skipping Validation: Not adding constraints like Field(min_length=1) or regex patterns. Add validation rules to the model.
  • Mixing Array Element Types: Not using Union types when arrays can contain multiple types. Use generics correctly.
  • Missing Aliases: Not mapping JSON camelCase to Python snake_case with Field aliases. Handle naming convention mismatches explicitly.

Integration Points

PhaseInput FromOutput ToContext
InputJSON response or API dataModel generationAnalyze JSON structure and infer types
DecompositionNested structuresSub-class extractionCreate separate Pydantic models for objects
IntegrationGenerated modelsimplementerUse in service layer for validation
ValidationModel with constraintsRuntime protectionPydantic validates all incoming data

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.