agentleFS
agentsdanceagentsdance/agentskills/skills/input-validator/SKILL.md

input-validator

Skill3 starsChanged 11 months agoApache-2.0View on GitHub

Implement input validation and sanitization. Use when the user needs to validate request data, sanitize user inputs, or create validation schemas.

The file

Files
SKILL.md

Input Validator

Validate and sanitize user inputs for security and data integrity.

Validation Libraries

LanguageLibrary
JavaScriptZod, Yup, Joi
PythonPydantic, Marshmallow
Govalidator

Zod (TypeScript)

import { z } from 'zod';

// Define schema
const userSchema = z.object({
  email: z.string().email(),
  password: z.string().min(8).max(100),
  age: z.number().int().positive().optional(),
  role: z.enum(['user', 'admin']).default('user'),
  tags: z.array(z.string()).max(10),
});

// Validate
const result = userSchema.safeParse(input);
if (!result.success) {
  console.log(result.error.format());
}

// Infer TypeScript type
type User = z.infer<typeof userSchema>;

// Transform and validate
const sanitizedSchema = z.object({
  email: z.string().email().toLowerCase().trim(),
  username: z.string()
    .min(3)
    .max(20)
    .regex(/^[a-zA-Z0-9_]+$/),
});

Pydantic (Python)

from pydantic import BaseModel, EmailStr, validator, Field
from typing import Optional, List

class UserCreate(BaseModel):
    email: EmailStr
    password: str = Field(min_length=8, max_length=100)
    age: Optional[int] = Field(None, gt=0, lt=150)
    tags: List[str] = Field(default_factory=list, max_items=10)

    @validator('password')
    def password_complexity(cls, v):
        if not any(c.isupper() for c in v):
            raise ValueError('must contain uppercase')
        if not any(c.isdigit() for c in v):
            raise ValueError('must contain digit')
        return v

# Usage
try:
    user = UserCreate(**data)
except ValidationError as e:
    print(e.json())

Express Middleware

import { z } from 'zod';

const validate = (schema) => (req, res, next) => {
  const result = schema.safeParse(req.body);
  if (!result.success) {
    return res.status(400).json({
      error: 'Validation failed',
      details: result.error.format(),
    });
  }
  req.body = result.data;
  next();
};

app.post('/users', validate(userSchema), createUser);

Common Validations

TypeValidation
EmailFormat, domain
PasswordLength, complexity
URLFormat, protocol
PhoneFormat, country
DateFormat, range

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.