Skip to content
Back to skills

Request Validation

ASecurity

Validate requests at the boundary with schemas, reject unknown fields, and return errors clients can act on. Use when hardening API input handling or standardizing validation across endpoints.

  • 7 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 5, 2026
ai-agentsrustapisecuritydocumentation

Works with

  • cli
  • api

Security analysis

A100/100

Scanned September 5, 2026

npx -y skills add Amey-Thakur/AI-SKILLS --skill request-validation --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Request Validation?

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

Security grade badge for Request Validation
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/amey-thakur-request-validation/badge)](https://www.skillsdirectory.com/skills/amey-thakur-request-validation)

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: request-validation
description: Validate requests at the boundary with schemas, reject unknown fields, and return errors clients can act on. Use when hardening API input handling or standardizing validation across endpoints.
---

# Request validation

Validate once, at the edge, into a typed value the rest of the code can
trust. Everything past the boundary should be impossible to construct
invalid.

## Method

1. **Schema-first, one schema per endpoint.** Define the request shape
   declaratively (JSON Schema via OpenAPI, zod, pydantic) and derive both
   the validator and the documentation from it. Hand-rolled if-chains
   drift from docs within a sprint.
2. **Parse, don't just check.** The validator's output is a typed object
   (trimmed strings, parsed dates, enum members), not the raw JSON plus a
   boolean. Downstream code taking `dict`/`any` re-validates forever.
3. **Reject unknown fields on writes.** A typo'd optional field
   (`descripton`) silently accepted is data loss the client discovers
   weeks later. Strictness on request bodies; tolerance is for what you
   read from others (be conservative in what you send, but validate what
   you accept).
4. **Layer the checks.** Shape and types (schema), then domain rules
   (ranges, formats, cross-field: `end > start`), then stateful rules
   (uniqueness, existence, permissions) inside the transaction where they
   are race-free. Shape failures are 400; semantic failures 422; state
   conflicts 409.
5. **Return all field errors at once, machine-readably.** Problem+json
   with a per-field list:
   `{"errors": [{"field": "email", "code": "format", "message": ...}]}`.
   One-error-at-a-time forces clients into a submit loop; codes let UIs
   localize (see api-error-responses).
6. **Bound everything.** Max body size, max string lengths, max array
   items, max nesting depth, at the schema and the server config both.
   Validation that allocates unbounded input first is a DoS vector, not a
   defense.
7. **Never echo hostile input raw.** Error messages include the field
   name and constraint, not megabytes of the offending value; log the
   details server-side with the request ID.

## Boundaries

- Validation is not sanitization: reject invalid input rather than
  mutating it into validity, except for benign normalization (trim,
  case-fold emails) that is documented.
- Authorization is not a validation layer concern; a well-formed request
  for someone else's resource is 404/403 territory decided in the
  handler (see authz-design).
- Client-side validation is UX; only the server's validation is a
  security boundary.

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.

Comments

Loading comments…