Validate Packs
Ensure your compiled packs are correct and production-ready.
Verify pack structure, catch errors, and enforce quality standards before deployment.
Prerequisites
Section titled “Prerequisites”- packc installed
- Compiled pack file (.pack.json)
Basic Validation
Section titled “Basic Validation”-
Compile your pack (if not already done)
Terminal window packc compile --config arena.yaml --output packs/app.pack.json --id app -
Run validation
Terminal window packc validate packs/app.pack.json -
Check the result
Success:
Validating pack: packs/app.pack.json✓ Pack is validWith warnings:
Validating pack: packs/app.pack.json⚠ Pack has 2 warnings:- Missing description for prompt 'support'- Tool 'search_kb' not defined
Validation Checks
Section titled “Validation Checks”PackC validates:
- Schema compliance - Pack structure matches spec
- Required fields - All mandatory fields present
- Prompt references - Prompts referenced in pack exist
- Tool definitions - Tools are properly defined
- Template syntax - Go templates are parseable
- Parameter types - Parameters have correct types
Validation Patterns
Section titled “Validation Patterns”Pattern 1: Validate After Every Compile
Section titled “Pattern 1: Validate After Every Compile”#!/bin/bashset -e
packc compile --config arena.yaml --output packs/app.pack.json --id apppackc validate packs/app.pack.json
echo "✓ Pack compiled and validated"Pattern 2: Validate All Packs
Section titled “Pattern 2: Validate All Packs”#!/bin/bash# validate-all.sh
for pack in packs/*.pack.json; do echo "Validating: $pack" packc validate "$pack"done
echo "✓ All packs validated"Pattern 3: Validate with Exit Codes
Section titled “Pattern 3: Validate with Exit Codes”#!/bin/bash# Validate and handle errors
if packc validate packs/app.pack.json; then echo "✓ Pack is valid" exit 0else echo "✗ Pack validation failed" exit 1fiPattern 4: Pre-Deployment Validation
Section titled “Pattern 4: Pre-Deployment Validation”#!/bin/bash# deploy.sh
echo "Pre-deployment checks..."
# Validate packif ! packc validate packs/prod/app.pack.json; then echo "✗ Pack validation failed - aborting deployment" exit 1fi
# Additional checks./scripts/test-pack.sh packs/prod/app.pack.json
echo "✓ Validation passed - proceeding with deployment"./scripts/deploy-pack.sh packs/prod/app.pack.jsonIntegration Patterns
Section titled “Integration Patterns”Pre-commit Hook
Section titled “Pre-commit Hook”Validate packs before committing:
#!/bin/bash# .git/hooks/pre-commit
echo "Validating packs before commit..."
for pack in $(git diff --cached --name-only | grep '\.pack\.json$'); do echo "Checking: $pack"
if ! packc validate "$pack"; then echo "✗ Validation failed for $pack" echo "Fix issues or use 'git commit --no-verify' to bypass" exit 1 fidone
echo "✓ All packs valid"Make it executable:
chmod +x .git/hooks/pre-commitMakefile Target
Section titled “Makefile Target”.PHONY: validatevalidate: @echo "Validating all packs..." @for pack in packs/*.pack.json; do \ echo "Checking $$pack..."; \ packc validate $$pack || exit 1; \ done @echo "✓ All packs validated"
.PHONY: validate-strictvalidate-strict: validate @echo "Running additional checks..." @./scripts/check-pack-size.sh @./scripts/check-prompt-quality.shCI/CD Pipeline
Section titled “CI/CD Pipeline”# .github/workflows/validate-packs.ymlname: Validate Packs
on: pull_request: paths: - 'packs/*.pack.json' - 'prompts/**' - 'config/**'
jobs: validate: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3
- name: Install packc run: go install github.com/AltairaLabs/PromptKit/tools/packc@latest
- name: Compile packs run: | packc compile --config arena.yaml --output packs/app.pack.json --id app
- name: Validate packs run: | for pack in packs/*.pack.json; do echo "Validating: $pack" packc validate "$pack" done
- name: Check pack quality run: | ./scripts/check-pack-quality.sh packs/*.pack.jsonAdvanced Validation
Section titled “Advanced Validation”Custom Validation Scripts
Section titled “Custom Validation Scripts”Create additional validation:
#!/bin/bash# scripts/validate-pack-quality.sh
pack_file="$1"
echo "Running quality checks on $pack_file..."
# Check pack sizesize=$(stat -f%z "$pack_file" 2>/dev/null || stat -c%s "$pack_file")max_size=$((1024 * 1024)) # 1MB
if [ "$size" -gt "$max_size" ]; then echo "✗ Pack too large: ${size} bytes (max: ${max_size})" exit 1fi
# Validate JSON syntaxif ! jq empty "$pack_file" 2>/dev/null; then echo "✗ Invalid JSON" exit 1fi
# Check for required metadataif ! jq -e '.compiler_version' "$pack_file" >/dev/null; then echo "✗ Missing compiler_version" exit 1fi
echo "✓ Quality checks passed"Validation Matrix
Section titled “Validation Matrix”Test packs across environments:
# .github/workflows/validate-matrix.ymlname: Validate Across Environments
on: [push, pull_request]
jobs: validate: strategy: matrix: environment: [dev, staging, prod]
runs-on: ubuntu-latest steps: - uses: actions/checkout@v3
- name: Install packc run: go install github.com/AltairaLabs/PromptKit/tools/packc@latest
- name: Compile $ pack run: | packc compile \ --config config/arena.$.yaml \ --output packs/$/app.pack.json \ --id app-$
- name: Validate pack run: packc validate packs/$/app.pack.jsonVerification
Section titled “Verification”Check Validation Status
Section titled “Check Validation Status”# Exit code 0 = valid, 1 = invalidpackc validate packs/app.pack.jsonecho $? # Should be 0Inspect Validation Results
Section titled “Inspect Validation Results”# Capture outputoutput=$(packc validate packs/app.pack.json 2>&1)
# Check for warningsif echo "$output" | grep -q "⚠"; then echo "Pack has warnings"fiTroubleshooting
Section titled “Troubleshooting”Validation fails with warnings
Section titled “Validation fails with warnings”Problem:
⚠ Pack has 1 warnings: - Missing description for prompt 'support'Solution: Fix warnings in source YAML:
spec: task_type: support description: "Customer support assistant" # Add missing descriptionThen recompile and validate:
packc compile --config arena.yaml --output packs/app.pack.json --id apppackc validate packs/app.pack.jsonPack file not found
Section titled “Pack file not found”Problem:
Error loading pack: open packs/app.pack.json: no such file or directorySolution: Compile pack first:
packc compile --config arena.yaml --output packs/app.pack.json --id apppackc validate packs/app.pack.jsonInvalid JSON
Section titled “Invalid JSON”Problem:
Error loading pack: invalid character '}' after top-level valueSolution: Recompile pack (don’t edit JSON manually):
packc compile --config arena.yaml --output packs/app.pack.json --id appTool not defined
Section titled “Tool not defined”Problem:
⚠ Tool 'search_kb' not definedSolution: Define tool in tools directory or prompt config:
# prompts/support.yamltools: - name: search_kb description: Search knowledge base input_schema: type: object properties: query: type: stringBest Practices
Section titled “Best Practices”1. Validate on Every Build
Section titled “1. Validate on Every Build”# Always pair compile with validatepackc compile --config arena.yaml --output packs/app.pack.json --id app && \packc validate packs/app.pack.json2. Fail Fast in CI
Section titled “2. Fail Fast in CI”- name: Validate packs run: | packc validate packs/*.pack.json # Fail pipeline if validation fails3. Track Validation History
Section titled “3. Track Validation History”# Log validation resultspackc validate packs/app.pack.json 2>&1 | tee validation-$(date +%Y%m%d).log4. Validate Before Tagging Releases
Section titled “4. Validate Before Tagging Releases”#!/bin/bash# scripts/release.sh
# Validate all packsfor pack in packs/prod/*.pack.json; do packc validate "$pack" || exit 1done
# Tag releasegit tag -a "v1.2.0" -m "Release v1.2.0"5. Create Validation Reports
Section titled “5. Create Validation Reports”#!/bin/bash# Generate validation report
cat > validation-report.txt <<EOFPack Validation Report=====================Date: $(date)Compiler: $(packc version)
EOF
for pack in packs/*.pack.json; do echo "Pack: $pack" >> validation-report.txt packc validate "$pack" 2>&1 >> validation-report.txt echo "" >> validation-report.txtdone
cat validation-report.txtNext Steps
Section titled “Next Steps”- Organize Pack Files - Structure your packs
- CI/CD Integration - Automate validation
- Inspect Packs - View pack details