validate-inputs

Check function inputs for correctness and safety. Use when implementing defensive programming.

⭐8stars🔀4forks📁View on GitHub🕐Updated Jan 3, 2026

When & Why to Use This Skill

The validate-inputs skill is a critical tool for defensive programming, designed to enhance software reliability and security. It automates the process of verifying function parameters, ensuring they adhere to specific data types, shapes, ranges, and formats. By catching malformed data at the entry point, it prevents runtime crashes and provides clear, actionable error messages, significantly improving the maintainability and robustness of complex codebases.

Use Cases

  • Defensive Programming: Automatically implementing runtime checks to ensure functions receive valid data, preventing silent failures and unexpected behavior.
  • Machine Learning & Data Science: Validating tensor shapes, dimensions, and dtypes before processing to ensure compatibility with model architectures.
  • API & Configuration Management: Verifying incoming request parameters and complex configuration objects to provide precise error feedback to users and developers.
  • Security Hardening: Mitigating vulnerabilities by sanitizing and validating inputs against strict specifications to prevent injection or data corruption issues.
namevalidate-inputs
description"Check function inputs for correctness and safety. Use when implementing defensive programming."
mcp_fallbacknone
categoryanalysis
tier2
user-invocablefalse

Validate Inputs

Implement input validation to ensure functions receive correct data types, shapes, ranges, and formats.

When to Use

  • Adding defensive checks to functions
  • Improving error messages for bad inputs
  • Ensuring tensor shape/dtype correctness
  • Validating configuration parameters

Quick Reference

# Input validation pattern
def validate_tensor(tensor):
    assert tensor is not None, "Tensor cannot be None"
    assert isinstance(tensor, ExTensor), "Must be ExTensor type"
    assert len(tensor.shape) > 0, "Tensor shape cannot be empty"
    assert tensor.dtype() in [DType.float32, DType.float64], "Invalid dtype"
    return True

# Usage with context
try:
    validate_tensor(input_data)
except AssertionError as e:
    raise ValueError(f"Invalid input: {e}")

Workflow

  1. Document expectations: Specify types, shapes, ranges for inputs
  2. Implement checks: Add validation before processing
  3. Provide error messages: Clear messages for validation failures
  4. Test edge cases: Verify validation catches invalid inputs
  5. Document behavior: Note what validation is performed

Output Format

Input validation specification:

  • Parameter name and type
  • Constraints (shape, range, valid values)
  • Error handling strategy
  • Error messages returned
  • Test cases for invalid inputs

References

  • See generate-tests skill for validation test cases
  • See CLAUDE.md > Defensive Programming for best practices
  • See scan-vulnerabilities skill for security validation