You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
motief/.mindmodel/patterns/validation.md

965 B

title category
Validation Pattern patterns

Validation Pattern

Rules

  • Validate inputs early and raise ValueError or domain-specific exceptions (ProviderError) for invalid contract inputs.
  • Tests should assert that invalid inputs raise the expected exceptions.
  • Use explicit checks for types and shapes on public APIs (e.g., ensure text is str before embedding).

Examples

ai_provider.py - Type validation

if not isinstance(text, str):
    raise ProviderError("text must be a string")

pipeline/ai_provider_wrapper.py - Defensive empty handling

if not texts:
    return []
if motion_ids is None:
    motion_ids = [None for _ in texts]

Anti-Patterns

Bad: Invalid values into computation

Problem: Allowing invalid values to propagate into heavy computation (e.g., non-string into embedding pipeline).

Remediation: Fail fast with a typed exception and add unit tests to cover validations.