03: Validation Workflows
Build a workflow that ensures pack quality before deployment.
Learning Objectives
Section titled “Learning Objectives”- Create automated validation workflows
- Catch errors before deployment
- Integrate validation in development
- Set up pre-commit validation
Time Required
Section titled “Time Required”25 minutes
Prerequisites
Section titled “Prerequisites”- Completed Tutorial 2: Multi-Prompt Packs
- Git installed
Step 1: Setup Project
Section titled “Step 1: Setup Project”mkdir validation-workflowcd validation-workflowmkdir -p prompts config packs scripts .git/hooksgit initStep 2: Create Prompts
Section titled “Step 2: Create Prompts”Create a sample prompt:
cat > prompts/assistant.yaml <<'EOF'apiVersion: promptkit.altairalabs.ai/v1alpha1kind: PromptConfigspec: task_type: assistant name: AI Assistant description: General purpose assistant system_prompt: You are a helpful AI assistant. user_template: "User: " template_engine: go parameters: temperature: 0.7 max_tokens: 500EOFCreate arena.yaml:
cat > config/arena.yaml <<'EOF'prompts: - ../prompts/assistant.yamlEOFStep 3: Create Validation Script
Section titled “Step 3: Create Validation Script”cat > scripts/validate-pack.sh <<'EOF'#!/bin/bashset -e
PACK_FILE="$1"
if [ -z "$PACK_FILE" ]; then echo "Usage: $0 <pack-file>" exit 1fi
echo "Validating: $PACK_FILE"
# 1. Check file existsif [ ! -f "$PACK_FILE" ]; then echo "❌ Pack file not found" exit 1fi
# 2. Validate with packcif ! packc validate "$PACK_FILE"; then echo "❌ Pack validation failed" exit 1fi
# 3. 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 "⚠ Warning: Pack size ${size} bytes exceeds recommended ${max_size} bytes"fi
# 4. Verify JSON structureif ! jq empty "$PACK_FILE" 2>/dev/null; then echo "❌ Invalid JSON" exit 1fi
# 5. Check required fieldsif ! jq -e '.id' "$PACK_FILE" >/dev/null; then echo "❌ Missing pack ID" exit 1fi
if ! jq -e '.prompts' "$PACK_FILE" >/dev/null; then echo "❌ Missing prompts" exit 1fi
echo "✅ Pack validation passed"EOF
chmod +x scripts/validate-pack.shStep 4: Build and Validate Workflow
Section titled “Step 4: Build and Validate Workflow”Create build script:
cat > scripts/build-and-validate.sh <<'EOF'#!/bin/bashset -e
echo "=== Building Packs ==="mkdir -p packs
packc compile \ --config config/arena.yaml \ --output packs/assistant.pack.json \ --id assistant
echo ""echo "=== Validating Packs ==="./scripts/validate-pack.sh packs/assistant.pack.json
echo ""echo "=== Inspecting Pack ==="packc inspect packs/assistant.pack.json
echo ""echo "✅ Build and validation complete"EOF
chmod +x scripts/build-and-validate.shRun it:
./scripts/build-and-validate.shStep 5: Pre-Commit Hook
Section titled “Step 5: Pre-Commit Hook”Set up automatic validation before commits:
cat > .git/hooks/pre-commit <<'EOF'#!/bin/bash
echo "Running pre-commit validation..."
# Compile all packsmkdir -p packspackc compile --config config/arena.yaml --output packs/assistant.pack.json --id assistant
# Validateif ! packc validate packs/assistant.pack.json; then echo "" echo "❌ Pack validation failed!" echo "Fix errors or use 'git commit --no-verify' to bypass" exit 1fi
echo "✅ Pre-commit validation passed"git add packs/assistant.pack.jsonEOF
chmod +x .git/hooks/pre-commitTest it:
git add prompts/ config/git commit -m "Add assistant prompt"Step 6: Makefile Workflow
Section titled “Step 6: Makefile Workflow”Create a Makefile for common workflows:
cat > Makefile <<'EOF'.PHONY: build validate clean test all
all: build validate
build: @echo "Building packs..." @mkdir -p packs @packc compile --config config/arena.yaml --output packs/assistant.pack.json --id assistant
validate: build @echo "Validating packs..." @./scripts/validate-pack.sh packs/assistant.pack.json
test: validate @echo "Running pack tests..." @# Add SDK tests here
clean: @echo "Cleaning build artifacts..." @rm -rf packs/
inspect: build @packc inspect packs/assistant.pack.jsonEOFUse it:
make build # Build packsmake validate # Build and validatemake all # Build and validatemake inspect # Build and inspectmake clean # Clean upStep 7: Continuous Validation
Section titled “Step 7: Continuous Validation”Create a validation loop for development:
cat > scripts/watch-and-validate.sh <<'EOF'#!/bin/bash
echo "Watching for changes..."
while true; do # Watch for changes to prompt files if find prompts/ -type f -mmin -0.1 | grep -q .; then echo "" echo "Changes detected, rebuilding..." make validate fi
sleep 1doneEOF
chmod +x scripts/watch-and-validate.shRun in a separate terminal:
./scripts/watch-and-validate.shWhat You Learned
Section titled “What You Learned”- ✅ Created validation scripts
- ✅ Built automated workflows
- ✅ Set up pre-commit hooks
- ✅ Used Makefiles for consistency
- ✅ Enabled continuous validation
Best Practices
Section titled “Best Practices”1. Always Validate
Section titled “1. Always Validate”# Never deploy without validationpackc compile ... && packc validate ...2. Fail Fast
Section titled “2. Fail Fast”# Stop on first errorset -e3. Multiple Validation Levels
Section titled “3. Multiple Validation Levels”# Basic: packc validate# Medium: + size checks# Strict: + custom validation rules4. Document Failures
Section titled “4. Document Failures”# Log validation resultspackc validate pack.json 2>&1 | tee validation.logNext Steps
Section titled “Next Steps”- Tutorial 4: Pack Management - Organize and version packs
- How-To: Validate Packs - More validation strategies
- How-To: CI/CD Integration - Automate in CI/CD
Summary
Section titled “Summary”You now have:
- Automated validation workflows
- Pre-commit quality gates
- Development validation loop
- Production-ready validation
Great work! 🎉