Back to Prompts
Coding Assistant

Validate API Request Data

For API input validation From the Input Validation AI Coding Building Block.

Prompt
Create validation for my API endpoints. I want to reject bad requests before they hit my business logic.

Framework: [Express, FastAPI, Django REST, etc.]
Validation library: [Zod, Pydantic, Marshmallow, Joi, or suggest one]

Validate these endpoints:
[POST /users - create user with email, password, name]
[PUT /users/:id - update user profile]
[POST /orders - create order with items array, shipping address]

For each endpoint:
1. Define a validation schema (types, required fields, formats)
2. Return clear error responses with field-level messages
3. Strip unknown fields to prevent mass assignment
4. Handle missing vs invalid vs malformed data differently

Show me how to reuse validation schemas across endpoints. I'm learning, so explain each validation choice.
0 views 0 copies