Skip to content
Back to skills

Data Validation Pydantic

ASecurity

Validates API payloads, files and config in Python with Pydantic v2 models, strict types and error reports a user can understand.

  • 3 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added November 15, 2026
ai-agentspythonexpressapi

Works with

  • api

Security analysis

A100/100

Scanned November 15, 2026

npx -y skills add workspace-templates/ai-agent-templates --skill data-validation-pydantic --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Data Validation Pydantic?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Data Validation Pydantic
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/workspace-templates-data-validation-pydantic/badge)](https://www.skillsdirectory.com/skills/workspace-templates-data-validation-pydantic)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: data-validation-pydantic
description: Validates API payloads, files and config in Python with Pydantic v2 models, strict types and error reports a user can understand.
---

# Data validation with Pydantic

Validate once at the edge, then pass typed models inward.

## Steps

1. Find boundaries: request bodies, queue messages, files, environment variables, third-party API responses. List what each should contain.
2. Write one `BaseModel` per shape. Use precise types (`EmailStr`, `HttpUrl`, `conint(ge=0)`, `Literal[...]`, `datetime`) instead of bare `str` and `int`.
3. Decide strictness per model. Use `model_config = ConfigDict(strict=True, extra="forbid")` for internal contracts so typos fail loudly. Keep coercion only where the source is text, such as CSV.
4. Express rules that span fields with `@model_validator(mode="after")` and single-field rules with `@field_validator`. Raise `ValueError` with a human message.
5. Parse with `Model.model_validate(data)` or `model_validate_json`. Never catch a bare exception; catch `ValidationError`.
6. Convert errors: loop over `e.errors()` and build `{"field": ".".join(map(str, err["loc"])), "problem": err["msg"]}`. Return all errors at once, not the first.
7. Use `SecretStr` for tokens and exclude them from output with `model_dump(exclude=...)`.
8. For settings, use `pydantic-settings` so missing variables fail at startup.

## Rules

- No `dict[str, Any]` crossing a function boundary when a model fits.
- Do not use v1 names (`parse_obj`, `validator`, `Config`).
- Add a test with one valid and three invalid payloads per model.

## Report

List models added, fields tightened, and any input that used to pass and now fails.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.