/validate

Development L2+ Production medium usage

/validate

Overview

/validate is a production command in the Development category of the Prismatic Platform. It performs comprehensive validation of inputs, data structures, configurations, and system state, enforcing data integrity rules across the umbrella codebase. The command validates everything from individual function inputs and Ecto changeset rules to cross-application configuration consistency and deployment readiness. It serves as both a development tool (validating code correctness) and an operational tool (validating system state before critical operations).

This command operates under the L2+ authority level and is executed by the validation-specialist agent. It is part of the platform's 216-command slash command registry, built on the AIAD (Autonomous Intelligence Agent Design) standard. The validation-specialist agent has expertise in Ecto changeset patterns, Phoenix parameter validation, schema verification, and cross-application consistency checking.

In a platform with 90+ umbrella applications sharing data through defined interfaces, validation failures at boundaries are a primary source of runtime errors. /validate addresses this by providing systematic validation at every boundary: function inputs against @spec types, Ecto changesets against schema constraints, API parameters against OpenApiSpex schemas, configuration values against expected types and ranges, and system state against operational invariants. The command can also generate validation code for modules that lack it, producing Ecto changeset functions, parameter validation plugs, and input sanitization logic.

Architecture

The validation system operates as a multi-layer verification pipeline.

Validation Architecture

             /validate
                 |
          Validation Orchestrator
                 |
          +------+------+------+
          |      |      |      |
       Input   Schema  Config  State
       Valid   Valid   Valid   Valid
          |      |      |      |
    +-----+-+ +--+--+ +-+--+ +--+--+
    |   |   | |  |  | |  |  | |  |  |
   Type Range Ecto API  Env  Runtime Inv
   Check Check Cast Spec Var  State  Check
    |   |   | |  |  | |  |  | |  |  |
    +---+---+-+--+--+-+--+--+-+--+--+
                 |
          Validation Report

Validation Layers

LayerScopeTechniqueCoverage
Input ValidationFunction parameters@spec type checking, guard clause verificationPublic functions
Schema ValidationData structuresEcto changeset, embedded schemaAll Ecto schemas
API ValidationHTTP parametersOpenApiSpex schema validationAll API endpoints
Config ValidationApplication configurationType checking, range verification, required keysAll config files
State ValidationRuntime system stateInvariant checking, health assessmentRunning application
Cross-App ValidationInterface contractsContract test verificationModule boundaries

Validation Types

TypeDescriptionExample
TypeValue matches expected typeis_binary(name), is_integer(score)
RangeValue within acceptable boundsscore >= 300 and score <= 900
FormatValue matches expected patternEmail format, URL format, UUID format
RequiredValue is present (not nil)not is_nil(domain)
ReferentialValue references existing entityForeign key exists in referenced table
Business RuleValue satisfies domain constraintend_date > start_date
ConsistencyValues are internally consistenttotal == sum(items)

Usage

# Validate specific module's input handling
/validate --module PrismaticPerimeter.SecurityRating

# Validate Ecto schema changesets
/validate --schema PrismaticPerimeter.Asset

# Validate application configuration
/validate --config prismatic_web

# Validate all API endpoint parameters
/validate --api prismatic_api

# Validate runtime system state
/validate --state

# Validate cross-application contracts
/validate --contracts

# Generate validation code for a module
/validate --generate PrismaticPerimeter.ComplianceAssessment

# Run all validation checks
/validate --all

# Export validation report
/validate --all --format json --export ./validation-report.json

# Dry run showing validation plan
/validate --dry-run --all

Practical Examples

# Pre-deployment validation of all configurations
/validate --config --all --environment production --verbose

# Validate Perimeter module data integrity
/validate --schema PrismaticPerimeter.Asset --schema PrismaticPerimeter.SecurityRating --verbose

# Generate comprehensive input validation for new module
/validate --generate PrismaticPerimeter.ScanResult --include-changesets --include-guards

# Cross-application contract validation
/validate --contracts --app "prismatic_web,prismatic_api,prismatic_perimeter" --verbose

# Runtime state validation before maintenance
/validate --state --checks "ets_tables,genservers,database_connections" --format json

Options

OptionTypeDefaultDescription
--modulestringnoneSpecific module to validate
--schemastringnoneSpecific Ecto schema to validate
--configstringnoneApplication configuration to validate
--apistringnoneAPI application to validate
--stateflagfalseValidate runtime system state
--contractsflagfalseValidate cross-application contracts
--generatestringnoneGenerate validation code for module
--allflagfalseRun all validation checks
--appstringallTarget application(s)
--environmentenumdevEnvironment: dev, staging, production
--verboseflagfalseDetailed validation results
--formatenumtextOutput format: text, json, markdown
--exportpathnoneExport validation report
--dry-runflagfalseShow validation plan without executing
--include-changesetsflagfalseInclude Ecto changeset generation
--include-guardsflagfalseInclude guard clause generation
--checksstringallSpecific state checks to run
--strictflagfalseFail on any validation warning

Execution Flow

Phase 1: Scope Resolution

The orchestrator determines the validation scope based on options. For --module, the target module is loaded and its public functions are extracted with their @spec types. For --schema, the Ecto schema definition is loaded with field types, validations, and constraints. For --config, configuration files are parsed and expected types are determined.

Phase 2: Rule Extraction

Validation rules are extracted from the codebase: @spec types become type checks, changeset functions become schema validations, guard clauses become range checks, and documentation annotations become business rule validations. For --generate mode, the system analyzes the module to infer appropriate validation rules.

Phase 3: Validation Execution

Rules are executed against the target. For static validation (module, schema, config), rules are checked against the code structure. For runtime validation (state), rules are checked against the live system. Each rule produces a pass/fail/warning result with specific evidence.

Phase 4: Cross-Reference Checking

Validation results are cross-referenced across applications. A schema field validated in one application is checked for consistent validation in consuming applications. API parameter types are verified against the calling code's expectations. Configuration values are checked for consistency across environments.

Phase 5: Reporting

Results are aggregated into a validation report showing: total checks run, pass/fail/warning counts, specific failure details with remediation suggestions, and overall validation health score. For --generate mode, the generated validation code is included in the output.

Integration Points

ComponentIntegration TypeDescription
/testPeerTests verify validation behavior
/codeUpstreamCode generation includes validation
/quality-gatesEnforcementValidation results affect gate passage
/security-auditPeerInput validation is a security concern
/route-testPeerRoute tests include parameter validation
EctoFrameworkChangeset validation infrastructure
OpenApiSpexFrameworkAPI parameter validation
TelemetryMonitoringValidation execution metrics

Best Practices

Validate at Boundaries

Focus validation at system boundaries: API endpoints, Phoenix controllers, GenServer handle_call/cast/info, and public module interfaces. Internal functions can rely on the boundary validation having already occurred. This produces the best balance of safety and performance.

Schema-Driven Validation

Let Ecto schemas drive validation through changeset functions. The changeset pattern provides a standard, composable approach to validation that integrates naturally with Phoenix forms, API processing, and database operations.

Early Validation

Validate inputs as early as possible in the processing pipeline. A malformed input caught at the API parameter level is far cheaper than one caught during database insertion. Use /validate --module to verify that public functions validate their inputs before processing.

Configuration Validation at Boot

Use /validate --config --environment production as part of the deployment pipeline. Configuration errors discovered at boot time (missing keys, wrong types, out-of-range values) are far less costly than those discovered during runtime under production load.

Error Handling

Error CodeDescriptionResolution
TYPE_MISMATCHValue does not match expected typeFix the value or update the type specification
RANGE_VIOLATIONValue outside acceptable rangeAdjust value or range constraints
REQUIRED_MISSINGRequired value is nil or absentProvide the required value
FORMAT_INVALIDValue does not match expected formatFix format or update format specification
CONTRACT_VIOLATIONCross-application contract mismatchAlign producer and consumer expectations
CONFIG_INVALIDConfiguration value fails validationFix configuration value
STATE_INVARIANT_BROKENRuntime state violates invariantInvestigate and restore valid state
GENERATION_FAILURECannot generate validation for moduleCheck module structure

Advanced Usage

Custom Validation Rules

Define project-specific validation rules:

/validate --custom-rules ./validation-rules/prismatic-rules.yaml --all

Validation Code Generation with Tests

Generate validation code with accompanying test suite:

/validate --generate PrismaticPerimeter.ScanResult --include-changesets --include-guards --include-tests

Continuous Validation

Set up continuous validation during development:

/validate --watch --module PrismaticPerimeter.SecurityRating --verbose

Doctrine Compliance

All commands operate under the NO MERCY, NO DOUBTS doctrine:

  • NO MERCY: Zero tolerance for incomplete execution or quality violations. Every public function must validate its inputs. Every Ecto schema must have changeset validation. No unvalidated data crosses application boundaries.
  • NO DOUBTS: Full investigation before action, evidence-based results. Every validation failure includes the specific rule violated, the invalid value, and a remediation suggestion.
  • /code - Core coding implementation and feature development
  • /test - Comprehensive test generation and verification
  • /fix - Bug fix implementation with mandatory regression tests
  • /security-audit - Comprehensive application security audit and vulnerability scan
  • /quality-gates - Enforce quality gate checkpoints with zero-warning compilation validation
  • /route-test - Route testing and HTTP endpoint verification
  • /regression-check - Execute 25 custom Credo regression checks preventing 700+ violations

Connect & Contribute

Created by Tomáš Korcak (korczis) | Open Source under GHL