Templates
Understanding template systems in PromptKit.
What is a Template?
Section titled “What is a Template?”A template is a reusable prompt structure with placeholders for dynamic content. Templates separate prompt logic from data.
Without Template
Section titled “Without Template”prompt := "You are a support agent for " + company + ". Help the user with: " + questionWith Template
Section titled “With Template”template := "You are a support agent for . Help the user with: "result := ExecuteTemplate(template, map[string]string{ "company": "TechCorp", "question": "password reset",})Why Use Templates?
Section titled “Why Use Templates?”Consistency: Same structure across all uses
Maintainability: Update once, apply everywhere
Reusability: Share templates across projects
Testing: Test templates independently
Versioning: Track template changes
Template Structure
Section titled “Template Structure”System and User Prompts
Section titled “System and User Prompts”system: | You are a for .
Guidelines: - Be - Keep responses under words
user: |Variables
Section titled “Variables”Variables are placeholders replaced with actual values:
variables := map[string]string{ "role": "customer support agent", "company": "TechCorp", "tone": "professional", "max_words": "100",}Templates in PromptKit Components
Section titled “Templates in PromptKit Components”Runtime Templates
Section titled “Runtime Templates”import "github.com/AltairaLabs/PromptKit/runtime/template"
// Create registrytemplates := template.NewRegistry()
// Register templatetemplates.RegisterTemplate("support", &template.PromptTemplate{ SystemPrompt: "You are a for .", Variables: map[string]string{ "role": "support agent", "company": "TechCorp", },})
// Use in pipelinepipe := pipeline.NewPipeline( middleware.TemplateMiddleware(templates, &middleware.TemplateConfig{ DefaultTemplate: "support", }), // ... other middleware)PackC Templates
Section titled “PackC Templates”PackC manages templates as files:
prompts/├── support.prompt├── sales.prompt└── technical.promptExample support.prompt:
name: supportversion: 1.0.0system: | You are a customer support agent for .
Your responsibilities: - Answer questions clearly - Be empathetic and professional - Escalate complex issues
Company info: - Website: - Support hours:
user: | Customer question:Package templates:
packc pack prompts/ -o templates.packLoad in code:
pack, _ := packc.LoadPack("templates.pack")template := pack.Templates["support"]SDK Templates
Section titled “SDK Templates”SDK uses simpler template approach:
conv := sdk.NewConversation(provider, &sdk.ConversationConfig{ SystemPrompt: "You are a helpful assistant for .", Variables: map[string]string{ "company": "TechCorp", },})Template Syntax
Section titled “Template Syntax”Variable Substitution
Section titled “Variable Substitution”Basic:
Hello, !With defaults:
Hello, !Conditionals
Section titled “Conditionals”system: | You are a support agent.
Provide priority support.system: | Available commands:
-Functions
Section titled “Functions”system: | User: Role:Template Best Practices
Section titled “Template Best Practices”Structure
Section titled “Structure”✅ Separate system and user prompts
system: | Instructions for AIuser: | User input:✅ Use clear variable names
not not✅ Provide defaults
tone:✅ Document variables
# Variables:# - company: Company name (required)# - role: Agent role (default: "support agent")# - hours: Support hours (default: "24/7")Organization
Section titled “Organization”✅ One template per use case
support.prompt # Customer supportsales.prompt # Sales inquiriestechnical.prompt # Technical support✅ Version templates
support-v1.promptsupport-v2.prompt✅ Use descriptive names
customer-support.prompt # Cleartemplate1.prompt # UnclearCommon Patterns
Section titled “Common Patterns”Role-Based Templates
Section titled “Role-Based Templates”name: role-basedsystem: | You are a .
Focus on helping customers resolve issues.
Focus on understanding customer needs.Multi-Language Templates
Section titled “Multi-Language Templates”name: multilingualsystem: |
You are a helpful assistant.
Eres un asistente útil.
Vous êtes un assistant utile.Contextual Templates
Section titled “Contextual Templates”name: contextualsystem: | You are a support agent.
User tier:
Provide white-glove support.
Provide standard support.
Previous issues:
This is a returning customer. Be extra helpful.Testing Templates
Section titled “Testing Templates”With PromptArena
Section titled “With PromptArena”name: Template Tests
templates: support: file: support.prompt variables: company: TechCorp role: support agent
tests: - name: Test Support Template template: support variables: question: "How do I reset my password?" assertions: - type: contains value: "TechCorp" - type: contains value: "password"With Runtime
Section titled “With Runtime”func TestTemplate(t *testing.T) { templates := template.NewRegistry() templates.RegisterTemplate("test", &template.PromptTemplate{ SystemPrompt: "You are a ", Variables: map[string]string{"role": "tester"}, })
// Test template rendering rendered := templates.Get("test").Render() assert.Contains(t, rendered, "tester")}Template Management
Section titled “Template Management”Development
Section titled “Development”- Create templates in
prompts/directory - Test locally with sample data
- Version control templates with code
- Document variables and usage
Production
Section titled “Production”- Package with PackC:
packc pack prompts/ -o prod.pack - Deploy with app: Include
.packfile - Load at runtime:
packc.LoadPack("prod.pack") - Monitor usage: Track which templates are used
Updates
Section titled “Updates”- Create new version:
support-v2.prompt - Test thoroughly: Use PromptArena
- Deploy gradually: Canary or blue-green
- Monitor metrics: Compare performance
- Rollback if needed: Switch back to v1
Troubleshooting
Section titled “Troubleshooting”Problem: Variable Not Substituted
Section titled “Problem: Variable Not Substituted”Output: "Hello, !" // Variable not replacedSolution: Check variable is provided
// Missing variablevariables := map[string]string{} // ❌
// Correctvariables := map[string]string{ "name": "Alice",} // ✅Problem: Template Not Found
Section titled “Problem: Template Not Found”Error: template "support" not foundSolution: Ensure template is registered
templates.RegisterTemplate("support", promptTemplate)Problem: Syntax Error
Section titled “Problem: Syntax Error”Error: unexpected "}" in templateSolution: Check template syntax
# Wrong{{.name} # Missing closing brace
# CorrectAdvanced Features
Section titled “Advanced Features”Nested Variables
Section titled “Nested Variables”system: | Company: Support:variables := map[string]any{ "company": map[string]string{ "name": "TechCorp", "support_email": "help@techcorp.com", },}Template Inheritance
Section titled “Template Inheritance”Base template:
# base.promptsystem: | You are a . Be professional and helpful.Extended template:
# support.promptextends: base.promptsystem: |
Additional guidelines: - Focus on customer satisfaction - Escalate when neededSummary
Section titled “Summary”Templates provide:
✅ Reusability - Write once, use many times
✅ Consistency - Same structure everywhere
✅ Maintainability - Update in one place
✅ Testability - Test independently
✅ Flexibility - Customize with variables
Related Documentation
Section titled “Related Documentation”- Prompts - Prompt engineering basics
- Runtime Templates - Implementation guide
- PackC Documentation - Template packaging
- Template Reference - API details