Validation Strategy
Understanding PackC’s approach to pack validation and quality assurance.
Overview
Section titled “Overview”PackC implements multi-level validation to catch errors early and ensure pack quality before deployment.
Validation Philosophy
Section titled “Validation Philosophy”Fail Fast
Section titled “Fail Fast”Catch errors at compile time, not runtime:
# Invalid prompt caught by packctask_type: "" # Error: task_type cannot be emptyBetter than runtime failure:
// Runtime error (bad!)conv, err := manager.NewConversation(ctx, pack, config)// Error: prompt not foundProgressive Validation
Section titled “Progressive Validation”Multiple checkpoints throughout compilation:
Parse → Validate Syntax → Validate Structure → Validate References → Final CheckEach stage catches different error types.
Warnings vs. Errors
Section titled “Warnings vs. Errors”Errors - Fatal, stop compilation:
Error: Missing required field 'task_type'Error: Invalid template syntaxWarnings - Non-fatal, allow compilation:
Warning: Missing description for prompt 'support'Warning: Tool 'search' not definedUse --strict mode to treat warnings as errors (future).
Validation Levels
Section titled “Validation Levels”Level 1: Syntax Validation
Section titled “Level 1: Syntax Validation”What: Valid YAML/JSON syntax
When: During parsing
Examples:
# Invalid YAMLprompts - support.yaml # Missing colonError:
Error parsing config: yaml: line 2: did not find expected keyLevel 2: Schema Validation
Section titled “Level 2: Schema Validation”What: Required fields present, correct types
When: After parsing
Check:
type PromptConfig struct { TaskType string `yaml:"task_type"` // Required SystemPrompt string `yaml:"system_prompt"` // Required UserTemplate string `yaml:"user_template"` // Optional}Errors:
Error: Missing required field 'task_type'Error: Field 'temperature' must be number, got stringLevel 3: Template Validation
Section titled “Level 3: Template Validation”What: Template syntax valid
When: During compilation
Check:
tmpl, err := template.New("test").Parse(userTemplate)if err != nil { return fmt.Errorf("Invalid template: %w", err)}Examples:
# Invalid Go templateuser_template: "Error:
Error: Template parse error: unclosed actionLevel 4: Reference Validation
Section titled “Level 4: Reference Validation”What: Referenced resources exist
When: After pack assembly
Check:
- Tools referenced in prompts are defined
- Fragments referenced exist
- Media files exist on disk
Warnings:
Warning: Tool 'search_kb' referenced but not definedWarning: Image file not found: images/logo.pngLevel 5: Semantic Validation
Section titled “Level 5: Semantic Validation”What: Logical consistency
When: Final validation pass
Check:
- No duplicate prompt IDs
- No circular fragment references
- Reasonable parameter values
- Pack size within limits
Warnings:
Warning: temperature=2.0 exceeds recommended max of 1.0Warning: Pack size 2MB exceeds recommended 1MBValidation Rules
Section titled “Validation Rules”Required Fields
Section titled “Required Fields”Pack Level:
{ "id": "required", "version": "required", "prompts": "required"}Prompt Level:
{ "id": "required", "name": "optional but recommended", "description": "optional but recommended", "system": "required (system or system_template)", "user_template": "optional", "parameters": "optional"}Type Validation
Section titled “Type Validation”String fields:
task_type: "support" # ✅ Validtask_type: 123 # ❌ Error: must be stringNumeric parameters:
temperature: 0.7 # ✅ Validtemperature: "0.7" # ❌ Error: must be numberBoolean fields:
debug: true # ✅ Validdebug: "true" # ❌ Error: must be booleanRange Validation
Section titled “Range Validation”Temperature: 0.0 to 2.0
temperature: 0.7 # ✅ Validtemperature: -1.0 # ⚠️ Warning: below 0temperature: 3.0 # ⚠️ Warning: above 2.0Max tokens: 1 to 100,000
max_tokens: 1000 # ✅ Validmax_tokens: 0 # ❌ Error: must be positivemax_tokens: 200000 # ⚠️ Warning: very largePattern Validation
Section titled “Pattern Validation”Pack ID: Alphanumeric with hyphens
id: "customer-support" # ✅ Validid: "Customer Support!" # ❌ Error: invalid charactersTask Type: Alphanumeric with hyphens/underscores
task_type: "support-agent" # ✅ Validtask_type: "support agent" # ❌ Error: no spacesTemplate Validation
Section titled “Template Validation”Go Templates:
# Validuser_template: "User: "user_template: ""
# Invaliduser_template: "user_template: "" # Unknown functionVariable References:
# Warning if variables not documenteduser_template: "" # ⚠️ Undocumented variableValidation Implementation
Section titled “Validation Implementation”Validation Pipeline
Section titled “Validation Pipeline”func (p *Pack) Validate() []string { var warnings []string
// 1. Validate pack structure warnings = append(warnings, p.validateStructure()...)
// 2. Validate each prompt for _, prompt := range p.Prompts { warnings = append(warnings, prompt.Validate()...) }
// 3. Validate references warnings = append(warnings, p.validateReferences()...)
// 4. Validate fragments warnings = append(warnings, p.validateFragments()...)
return warnings}Validation Context
Section titled “Validation Context”Provide context for errors:
type ValidationError struct { Field string // Which field Value interface{} // Actual value Message string // Error description File string // Source file Line int // Line number}Error Message:
Error in prompts/support.yaml: Line 8: Missing required field 'task_type'
7: spec: 8: name: Support Agent 9: system_prompt: ...Validation Strategies
Section titled “Validation Strategies”Strict Mode
Section titled “Strict Mode”Treat warnings as errors:
packc compile --strictUse for:
- Production builds
- CI/CD pipelines
- Release candidates
Lenient Mode (default)
Section titled “Lenient Mode (default)”Allow warnings:
packc compileUse for:
- Development
- Quick iteration
- Testing
Custom Validation
Section titled “Custom Validation”Add custom rules (future):
# .packc-rules.yamlvalidation: rules: - name: require-descriptions level: error check: prompt.description != ""
- name: max-system-prompt-length level: warning check: len(prompt.system) < 1000Pre-Deployment Validation
Section titled “Pre-Deployment Validation”Validation Checklist
Section titled “Validation Checklist”Before deploying to production:
1. Schema valid
packc validate pack.json2. Size acceptable
du -h pack.json# Should be < 1MB3. JSON valid
jq empty pack.json4. Required metadata present
jq -e '.compiler_version' pack.jsonjq -e '.version' pack.json5. Load test
# Test with SDKgo run test-pack.go pack.jsonAutomated Validation
Section titled “Automated Validation”In CI/CD:
- name: Validate packs run: | packc compile --config arena.yaml --output pack.json --id app packc validate pack.json
# Additional checks ./scripts/check-pack-size.sh pack.json ./scripts/test-pack-load.sh pack.jsonValidation Reports
Section titled “Validation Reports”Summary Report
Section titled “Summary Report”packc validate pack.jsonOutput:
Validating pack: pack.json
Pack Information: ID: customer-support Version: 1.0.0 Prompts: 3
✓ Schema valid✓ All prompts valid✓ All references valid
⚠️ Warnings: 2 - Missing description for prompt 'support' - Tool 'search_kb' referenced but not defined
Summary: Pack is valid with 2 warningsDetailed Report (future)
Section titled “Detailed Report (future)”packc validate pack.json --detailedOutput:
Validation Report=================
Pack: customer-support v1.0.0Compiler: packc-v0.1.0Validated: 2025-01-16T10:30:00Z
Schema Validation: ✅ PASS - Pack ID present - Version valid (1.0.0) - 3 prompts found
Prompt Validation: ✅ PASS - greeting: ✅ Valid - support: ⚠️ Missing description - escalation: ✅ Valid
Reference Validation: ⚠️ WARNINGS - Tool 'search_kb': not defined - Tool 'create_ticket': not defined
Template Validation: ✅ PASS - All templates syntactically valid - 2 variables used: name, message
Fragment Validation: ✅ PASS - No fragments used
Size Analysis: - Pack size: 45 KB - Estimated load time: 5ms - Memory footprint: ~100 KB
Overall: ✅ VALID (2 warnings)Validation Best Practices
Section titled “Validation Best Practices”1. Validate Early
Section titled “1. Validate Early”# During developmentpackc compile && packc validate2. Validate Often
Section titled “2. Validate Often”# Pre-commit hookpackc validate pack.json || exit 13. Automate Validation
Section titled “3. Automate Validation”.PHONY: validatevalidate: packc validate packs/*.pack.json4. Track Warnings
Section titled “4. Track Warnings”# Log warningspackc validate pack.json 2>&1 | tee validation.log5. Fix Warnings
Section titled “5. Fix Warnings”Don’t ignore warnings - they indicate potential issues:
# Badtask_type: support# Warning: Missing description
# Goodtask_type: supportdescription: "Handles customer support inquiries"Validation Evolution
Section titled “Validation Evolution”Current (v0.1.0)
Section titled “Current (v0.1.0)”- Schema validation
- Template syntax checking
- Basic reference checking
- Size warnings
Planned (v0.2.0)
Section titled “Planned (v0.2.0)”- Semantic validation
- Custom validation rules
- Validation profiles
- Detailed reports
Future (v1.0.0)
Section titled “Future (v1.0.0)”- ML-based validation (detect poor prompts)
- Security scanning
- Performance predictions
- Quality scoring
Summary
Section titled “Summary”PackC’s validation strategy:
- Multi-level - Syntax, schema, references, semantics
- Progressive - Validation at each pipeline stage
- Informative - Clear error messages with context
- Flexible - Warnings vs. errors, strict mode
- Automated - Easy to integrate in workflows
- Evolving - Continuous improvement
This ensures packs are correct, complete, and production-ready before deployment.