| name | data-validator |
| description | Validates data against specified rules including required field checks, email format validation, and numeric type verification. Use when the user needs to verify data integrity, validate form inputs, or check data against business rules. |
| license | MIT |
| metadata | {"author":"agent-skills-poc","version":"1.0","category":"validation"} |
Data Validator Skill
This skill validates data structures against specified validation rules.
When to Use
Use this skill when:
- The user needs to validate form data or user inputs
- Data integrity needs to be verified
- Email addresses need format validation
- Required fields need to be checked
- Numeric type validation is needed
- The user mentions terms like "validate", "check data", "verify", "validation rules", "required fields"
Instructions
Step 1: Understand the Validation Rules
Identify which validation rules to apply:
- Required fields: Fields that must be present and non-empty
- Email fields: Fields that must contain valid email addresses
- Numeric fields: Fields that must contain numeric values
Step 2: Check Required Fields
For each field in the required fields list:
- Check if the field exists in the data
- Check if the field value is not null
- Check if the field value is not undefined
- Check if the field value is not an empty string
- If any check fails, add an error: "Field '[field_name]' is required"
Step 3: Validate Email Fields
For each field in the email fields list:
- Check if the field exists in the data
- If it exists and is a string, validate the email format:
- Must contain exactly one @ symbol
- Must have characters before the @
- Must have characters after the @
- Must have a dot (.) after the @
- Must have characters after the final dot
- If validation fails, add an error: "Field '[field_name]' must be a valid email address"
Step 4: Validate Numeric Fields
For each field in the numeric fields list:
- Check if the field exists in the data
- If it exists, check if the value is of type number
- If not a number, add an error: "Field '[field_name]' must be a number"
Step 5: Report Results
- Collect all validation errors
- If no errors: Report that validation passed
- If errors exist: List all validation errors clearly
Examples
Example 1: Valid User Data
Input:
- Data:
{ name: "John Doe", email: "john@example.com", age: 30 }
- Rules: Required fields: ["name", "email"], Email fields: ["email"], Numeric fields: ["age"]
Steps:
- Check required fields:
- Check email format:
- Check numeric fields:
- No errors found
Output: "Validation passed. All fields are valid."
Example 2: Missing Required Field
Input:
- Data:
{ email: "john@example.com" }
- Rules: Required fields: ["name", "email"]
Steps:
- Check required fields:
- "name" does not exist ✗
- "email" exists ✓
- Error found: "Field 'name' is required"
Output: "Validation failed with 1 error: Field 'name' is required"
Example 3: Invalid Email Format
Input:
- Data:
{ name: "John", email: "invalid-email" }
- Rules: Required fields: ["name", "email"], Email fields: ["email"]
Steps:
- Check required fields: Both exist ✓
- Check email format:
- "invalid-email" does not contain @ ✗
- Error found: "Field 'email' must be a valid email address"
Output: "Validation failed with 1 error: Field 'email' must be a valid email address"
Example 4: Multiple Validation Errors
Input:
- Data:
{ name: "", email: "bad-email", age: "25" }
- Rules: Required fields: ["name", "email"], Email fields: ["email"], Numeric fields: ["age"]
Steps:
- Check required fields:
- "name" is empty string ✗
- "email" exists ✓
- Check email format:
- "bad-email" invalid format ✗
- Check numeric fields:
- "age" is "25" (string, not number) ✗
- Three errors found
Output:
Validation failed with 3 errors:
1. Field 'name' is required
2. Field 'email' must be a valid email address
3. Field 'age' must be a number
Example 5: Optional Fields
Input:
- Data:
{ name: "John", phone: "123-456-7890" }
- Rules: Required fields: ["name"], Email fields: ["email"]
Steps:
- Check required fields:
- Check email fields:
- "email" field not in data, but not required, so skip ✓
- "phone" field exists but no rules apply to it ✓
- No errors found
Output: "Validation passed. All required fields are valid."
Common Edge Cases
- Empty strings: Treat as missing for required field validation
- Null vs undefined: Both should fail required field validation
- Whitespace-only strings: Consider whether to treat as empty
- Case sensitivity: Email validation should be case-insensitive
- Numeric strings: "123" as a string should fail numeric validation
- Zero values: 0 is a valid number and should pass numeric validation
- Extra fields: Fields not mentioned in rules should be ignored
- Email edge cases: Handle emails with multiple dots, plus signs, etc.
Email Validation Pattern
A valid email must match this pattern:
- Format:
local-part@domain
- Local part: One or more characters before @
- Domain: One or more characters, must contain at least one dot
- Example valid emails:
user@example.com, john.doe@company.co.uk, test+tag@domain.com
- Example invalid emails:
@example.com, user@, user, user@domain, user @example.com
Tips
- Always list all validation errors, not just the first one
- Be specific in error messages (include the field name)
- Consider the order of validation (check required first, then format)
- Provide clear feedback on what passed and what failed
- If validating multiple records, validate each independently