compile-prompt
Compile a single prompt YAML file into pack format.
Synopsis
Section titled “Synopsis”packc compile-prompt --prompt <yaml-file> --output <json-file> [options]Description
Section titled “Description”The compile-prompt command compiles a single prompt YAML configuration file into a standalone pack JSON file. This is useful for:
- Testing individual prompts during development
- Creating single-prompt packs for specialized use cases
- Compiling prompts independently of the main arena.yaml
- Quick iteration on prompt development
Unlike the compile command which processes all prompts from arena.yaml, compile-prompt focuses on a single prompt file and produces a minimal pack containing only that prompt.
Options
Section titled “Options”Required Options
Section titled “Required Options”--prompt <path>
- Path to the prompt YAML file to compile
- The YAML must contain a valid PromptConfig structure
- Relative paths are resolved from the current directory
--output <path>
- Output pack file path
- Must end with
.jsonor.pack.json - Parent directory will be created if it doesn’t exist
Optional Options
Section titled “Optional Options”--config-dir <path>
- Base directory for resolving config files
- Default: current directory
- Used for resolving relative paths in media references
Examples
Section titled “Examples”Basic Single Prompt Compilation
Section titled “Basic Single Prompt Compilation”packc compile-prompt \ --prompt prompts/support.yaml \ --output packs/support.pack.jsonWith Custom Config Directory
Section titled “With Custom Config Directory”packc compile-prompt \ --prompt prompts/marketing/email.yaml \ --output packs/marketing-email.pack.json \ --config-dir ./configCompile for Testing
Section titled “Compile for Testing”# Compile to temporary location for testingpackc compile-prompt \ --prompt prompts/experimental/new-feature.yaml \ --output /tmp/test-feature.pack.jsonMultiple Single Prompts
Section titled “Multiple Single Prompts”# Compile several prompts individuallyfor prompt in prompts/*.yaml; do name=$(basename "$prompt" .yaml) packc compile-prompt \ --prompt "$prompt" \ --output "packs/${name}.pack.json"doneInput Format
Section titled “Input Format”The prompt YAML file must contain a valid PromptConfig structure:
# prompts/support.yamlapiVersion: promptkit.altairalabs.ai/v1alpha1kind: PromptConfigspec: task_type: customer-support name: Customer Support Agent description: Handles customer inquiries system_prompt: | You are a helpful customer support agent. You assist customers with their questions.
user_template: | Customer:
template_engine: go
parameters: temperature: 0.7 max_tokens: 1000 top_p: 0.9
tools: - name: search_knowledge_base description: Search the knowledge baseOutput Format
Section titled “Output Format”The command produces a JSON pack file with this structure:
{ "id": "customer-support", "version": "1.0.0", "compiler_version": "packc-v0.1.0", "prompts": { "customer-support": { "id": "customer-support", "name": "Customer Support Agent", "description": "Handles customer inquiries", "system": "You are a helpful customer support agent.\nYou assist customers with their questions.", "user_template": "Customer: ", "template_engine": "go", "parameters": { "temperature": 0.7, "max_tokens": 1000, "top_p": 0.9 }, "tools": ["search_knowledge_base"] } }, "metadata": { "source_file": "prompts/support.yaml", "compiled_at": "2025-01-16T10:30:00Z" }}Compilation Process
Section titled “Compilation Process”The compile-prompt command performs these steps:
- Read YAML File - Load and parse the prompt YAML
- Validate Structure - Ensure PromptConfig is valid
- Check Media References - Validate any media file paths
- Create Registry - Build in-memory prompt registry
- Compile Pack - Generate optimized pack JSON
- Write Output - Save pack to specified file
Exit Codes
Section titled “Exit Codes”- 0 - Successful compilation
- 1 - Error occurred (see error message)
Common Errors
Section titled “Common Errors”Invalid YAML Syntax
Section titled “Invalid YAML Syntax”Error parsing prompt config: yaml: line 5: mapping values are not allowed in this contextSolution: Check YAML indentation and syntax. Use a YAML validator.
Missing Required Fields
Section titled “Missing Required Fields”Error parsing prompt config: missing required field: task_typeSolution: Ensure the prompt YAML includes all required fields (task_type, system_prompt).
Media File Not Found
Section titled “Media File Not Found”⚠ Media validation warnings: - Image file not found: images/logo.pngSolution: Ensure media files exist at specified paths. Use --config-dir to set base directory.
Invalid Template Syntax
Section titled “Invalid Template Syntax”Compilation failed: template parse error: unexpected "}" in operandSolution: Check Go template syntax in user_template or system_prompt. Ensure “ are balanced.
Output Directory Missing
Section titled “Output Directory Missing”Failed to write pack file: no such file or directorySolution: Create output directory first or use mkdir:
mkdir -p packspackc compile-prompt --prompt prompts/support.yaml --output packs/support.pack.jsonWarnings
Section titled “Warnings”The compile-prompt command may display warnings that don’t prevent compilation:
Media Reference Warnings
Section titled “Media Reference Warnings”⚠ Media validation warnings: - Image file not found: assets/banner.jpg - Video file missing: media/intro.mp4These warnings indicate missing media files referenced in the prompt. The pack will compile, but media content may not work at runtime.
Integration
Section titled “Integration”Pre-commit Hook
Section titled “Pre-commit Hook”#!/bin/bash# .git/hooks/pre-commit# Compile modified prompts before commit
for file in $(git diff --cached --name-only | grep '^prompts/.*\.yaml$'); do name=$(basename "$file" .yaml) echo "Compiling $file..." packc compile-prompt --prompt "$file" --output "packs/${name}.pack.json"
if [ $? -ne 0 ]; then echo "❌ Failed to compile $file" exit 1 fi
git add "packs/${name}.pack.json"doneMakefile Target
Section titled “Makefile Target”.PHONY: compile-promptscompile-prompts: @mkdir -p packs @for prompt in prompts/*.yaml; do \ name=$$(basename $$prompt .yaml); \ echo "Compiling $$prompt..."; \ packc compile-prompt --prompt $$prompt --output packs/$$name.pack.json; \ done
.PHONY: compile-singlecompile-single: @if [ -z "$(PROMPT)" ]; then \ echo "Usage: make compile-single PROMPT=prompts/support.yaml"; \ exit 1; \ fi @packc compile-prompt --prompt $(PROMPT) --output $(OUTPUT)Usage:
# Compile all prompts individuallymake compile-prompts
# Compile specific promptmake compile-single PROMPT=prompts/support.yaml OUTPUT=packs/support.pack.jsonCI/CD Pipeline
Section titled “CI/CD Pipeline”# .github/workflows/compile-single-prompts.ymlname: Compile Modified Prompts
on: pull_request: paths: - 'prompts/*.yaml'
jobs: compile: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3
- name: Install packc run: go install github.com/AltairaLabs/PromptKit/tools/packc@latest
- name: Detect modified prompts id: changed-files uses: tj-actions/changed-files@v40 with: files: prompts/*.yaml
- name: Compile modified prompts if: steps.changed-files.outputs.any_changed == 'true' run: | mkdir -p packs for file in $; do name=$(basename "$file" .yaml) echo "Compiling $file..." packc compile-prompt --prompt "$file" --output "packs/${name}.pack.json" done
- name: Upload packs uses: actions/upload-artifact@v3 with: name: compiled-packs path: packs/*.pack.jsonDevelopment Workflow
Section titled “Development Workflow”Quick Test Cycle
Section titled “Quick Test Cycle”# Edit promptvim prompts/support.yaml
# Compile for testingpackc compile-prompt \ --prompt prompts/support.yaml \ --output /tmp/test-support.pack.json
# Test with SDKgo run cmd/test/main.go --pack /tmp/test-support.pack.jsonOrganize by Environment
Section titled “Organize by Environment”# Developmentpackc compile-prompt \ --prompt prompts/dev/support.yaml \ --output packs/dev/support.pack.json
# Stagingpackc compile-prompt \ --prompt prompts/staging/support.yaml \ --output packs/staging/support.pack.json
# Productionpackc compile-prompt \ --prompt prompts/prod/support.yaml \ --output packs/prod/support.pack.jsonBest Practices
Section titled “Best Practices”1. Use Descriptive Filenames
Section titled “1. Use Descriptive Filenames”# Goodpackc compile-prompt \ --prompt prompts/customer-support-v2.yaml \ --output packs/customer-support-v2.pack.json
# Avoidpackc compile-prompt \ --prompt prompts/temp.yaml \ --output packs/out.json2. Validate After Compilation
Section titled “2. Validate After Compilation”packc compile-prompt --prompt prompts/support.yaml --output packs/support.pack.jsonpackc validate packs/support.pack.json3. Version Individual Prompts
Section titled “3. Version Individual Prompts”# Include version in filenamepackc compile-prompt \ --prompt prompts/support.yaml \ --output "packs/support-$(date +%Y%m%d).pack.json"4. Use Scripts for Batch Operations
Section titled “4. Use Scripts for Batch Operations”#!/bin/bash# compile-all-prompts.sh
for prompt in prompts/*.yaml; do name=$(basename "$prompt" .yaml) echo "Compiling: $name"
packc compile-prompt \ --prompt "$prompt" \ --output "packs/${name}.pack.json"
if [ $? -eq 0 ]; then echo "✓ Compiled: packs/${name}.pack.json" else echo "✗ Failed: $prompt" exit 1 fidone
echo "✓ All prompts compiled successfully"See Also
Section titled “See Also”- compile command - Compile all prompts from arena.yaml
- validate command - Validate compiled packs
- inspect command - Inspect pack contents
- Pack Format - Pack structure details