CLI Validation Commands
AgentMap provides comprehensive CLI validation commands built on the runtime facade pattern to ensure your workflows, configuration files, and system setup are correct before execution. These commands integrate seamlessly with development workflows and CI/CD pipelines.
Validation Architectureâ
Facade Pattern Implementationâ
All validation commands follow AgentMap's facade pattern, using runtime_api.py for business logic and cli_presenter.py for consistent output:
# Standard validation command pattern
from agentmap import validate_workflow
from agentmap.deployment.cli.utils.cli_presenter import print_json, print_err, map_exception_to_exit_code
def validate_command(args):
try:
# Use runtime facade for validation logic
result = validate_workflow(graph_name, config_file=args.config)
# Use CLI presenter for consistent output
print_json(result)
except Exception as e:
print_err(str(e))
exit_code = map_exception_to_exit_code(e)
raise typer.Exit(code=exit_code)
Runtime API Integrationâ
Validation commands use these runtime facade functions:
| Function | Purpose | Commands Using |
|---|---|---|
validate_workflow() | CSV and graph validation | validate |
validate_cache() | Cache integrity checking | validate-cache |
ensure_initialized() | Runtime system validation | Most commands |
CLI Presenter Integrationâ
All validation commands use the standardized CLI presenter utilities:
- Consistent Error Handling: Maps validation exceptions to appropriate exit codes
- JSON Output: Structured validation results with custom encoding for AgentMap objects
- Stderr Management: Error messages output to stderr for script compatibility
Bundle-Based Validationâ
The validation system uses bundle analysis to provide comprehensive workflow validation:
# Example validation workflow
def validate_command(csv_file, graph, config_file):
try:
# Resolve CSV path using utility functions
csv_path = resolve_csv_path(csv_file, csv)
# Use runtime facade for validation
result = validate_workflow(graph_name, config_file=config_file)
# Bundle analysis results
outputs = result["outputs"]
metadata = result["metadata"]
# Report comprehensive validation results
print(f"Total nodes: {outputs['total_nodes']}")
print(f"Total edges: {outputs['total_edges']}")
if outputs["missing_declarations"]:
print(f"Missing agents: {', '.join(outputs['missing_declarations'])}")
except Exception as e:
handle_command_error(e, verbose=False)
Validation Pattern Benefitsâ
Facade Pattern Advantages:
- Consistent Interface: All validation commands use the same runtime facade
- Error Standardization: Unified exception handling and exit code mapping
- Output Formatting: Consistent JSON output with custom AgentMap object encoding
- Business Logic Separation: Validation logic encapsulated in the runtime layer
CLI Presenter Benefits:
- Script Compatibility: Structured JSON output for automation
- Human Readability: Optional pretty formatting for development
- Error Handling: Standardized stderr output and exit codes
Command Overviewâ
The validation system provides several specialized commands:
agentmap validate csv: Validate CSV workflow files with graph consistency checksagentmap validate config: Validate YAML configuration files with schema validationagentmap validate all: Comprehensive validation of both CSV and config filesagentmap validate cache: Manage validation cache for performance optimization
CSV Validation Commandâ
Validate CSV workflow definition files with comprehensive structure and logic checks.
Basic Usageâ
agentmap validate csv [OPTIONS]
Optionsâ
| Option | Short | Description | Default |
|---|---|---|---|
--csv | -c | Path to CSV file to validate | Uses config default |
--no-cache | Skip cache and force re-validation | false | |
--config | Path to custom config file | agentmap_config.yaml |
Examplesâ
Validate Specific CSV File:
agentmap validate csv --csv workflows/customer_onboarding.csv
Force Fresh Validation (Bypass Cache):
agentmap validate csv --csv workflows/customer_onboarding.csv --no-cache
Use Custom Configuration:
agentmap validate csv --csv workflows/flow.csv --config configs/development.yaml
Validate Default CSV (from config):
agentmap validate csv
Sample Outputâ
Successful Validation:
đ Validating CSV file: workflows/customer_onboarding.csv
â
CSV file format is valid
âšī¸ CSV contains 12 rows and 7 columns
âšī¸ Found 1 graph(s): 'customer_onboarding' (12 nodes)
âšī¸ Found 4 unique agent types: GPTAgent, HumanAgent, EmailAgent, ValidationAgent
âšī¸ Graph 'customer_onboarding' has multiple potential entry points: 'start', 'manual_entry'
âšī¸ Node 'final_approval' has no outgoing edges (terminal node)
â
CSV validation passed!
Validation with Issues:
đ Validating CSV file: workflows/broken_workflow.csv
â CSV Validation Errors:
1. Duplicate node 'validate_email' in graph 'customer_flow'
Line 5
2. Node 'process_payment' references non-existent target 'send_confirmtion' in Edge
Line 6, Field: Edge, Value: send_confirmtion
Suggestion: Valid targets: validate_email, process_payment, send_confirmation
â ī¸ CSV Validation Warnings:
1. Unknown agent type: 'GPTAgnet'
Line 3, Field: AgentType, Value: GPTAgnet
Suggestion: Check spelling or ensure agent is properly registered/available
2. Node 'complex_analysis' has a large prompt (500+ characters)
Line 8, Field: Prompt
Suggestion: Consider breaking into smaller, focused prompts
âšī¸ Validation complete with 2 errors and 2 warnings
Validation Checks Performedâ
Structure Validation:
- Required columns presence (
GraphName,Node) - Optional columns recognition
- Column alias support and normalization
- Data format and consistency
Row-Level Validation:
- Required field completeness
- Input/Output field format validation
- Routing logic consistency
- Field value constraints
Graph Consistency:
- Duplicate node detection within graphs
- Node reference validation
- Entry and terminal point identification
- Routing path verification
Agent Validation:
- Agent type availability checking
- Agent registry verification
- Custom agent accessibility
Config Validation Commandâ
Validate YAML configuration files with comprehensive schema and environment checks.
Basic Usageâ
agentmap validate config [OPTIONS]
Optionsâ
| Option | Short | Description | Default |
|---|---|---|---|
--config | -c | Path to config file to validate | agentmap_config.yaml |
--no-cache | Skip cache and force re-validation | false |
Examplesâ
Validate Default Configuration:
agentmap validate config
Validate Specific Configuration:
agentmap validate config --config configs/production.yaml
Force Fresh Validation:
agentmap validate config --config configs/staging.yaml --no-cache
Sample Outputâ
Successful Validation: