Skip to main content

Your First Advanced Template

This hands-on tutorial will guide you through creating a sophisticated template system for prompt engineering workflows. You'll learn to use Petk's advanced features including glob patterns, variable substitution, and dynamic content assembly.

What We're Building​

We'll create a prompt engineering system for generating AI assistant personas with:

  • Dynamic role assembly from reusable components
  • Variable-driven customization
  • Hierarchical template organization
  • Advanced content inclusion patterns

By the end, you'll have a flexible system for generating consistent, professional AI prompts.

Prerequisites​

  • Completed the Getting Started guide
  • Basic understanding of Markdown syntax
  • Familiarity with YAML configuration

Project Setup​

1. Create the Project Structure​

mkdir ai-persona-prompts
cd ai-persona-prompts
petk init

2. Configure the Project​

Edit petk.config.yaml:

input_dir: "./templates"
output_dir: "./output"
variables:
# Project metadata
project_name: "AI Persona Generator"
version: "1.0.0"

# Default persona settings
default_expertise: "general assistance"
default_tone: "professional and helpful"
default_constraints: "ethical and factual"

# Template processing
max_depth: 5
enable_sampling: true

Building the Template System​

3. Create Base Components​

First, create reusable building blocks in templates/components/:

templates/components/personality-traits.md:

## Personality Traits

You embody the following characteristics:

- **Expertise**: `\{\{expertise\}\}`
- **Communication Style**: `\{\{tone\}\}`
- **Core Constraints**: `\{\{constraints\}\}`
- **Response Approach**: Thorough, accurate, and contextually appropriate

### Communication Guidelines

- Provide clear, structured responses
- Ask clarifying questions when needed
- Acknowledge limitations appropriately
- Maintain consistency throughout conversations

templates/components/ethical-framework.md:

## Ethical Framework

Your responses must adhere to these principles:

1. **Accuracy**: Provide factual, well-researched information
2. **Transparency**: Acknowledge uncertainties and limitations
3. **Respect**: Treat all individuals and perspectives with dignity
4. **Safety**: Avoid harmful, dangerous, or inappropriate content
5. **Privacy**: Respect confidentiality and personal information

templates/components/response-format.md:

## Response Structure

Structure your responses using this framework:

### Understanding
- Acknowledge the user's question or request
- Identify key requirements and context

### Analysis
- Break down complex topics into manageable parts
- Consider multiple perspectives when relevant

### Solution/Answer
- Provide clear, actionable information
- Include examples or illustrations when helpful

### Next Steps
- Suggest follow-up questions or related topics
- Offer additional resources when appropriate

4. Create Specialized Skill Sets​

Create domain-specific components in templates/skills/:

templates/skills/technical-writing.md:

## Technical Writing Expertise

### Core Competencies
- Documentation architecture and information design
- Technical communication for diverse audiences
- Content strategy and user experience
- API documentation and developer resources

### Specialized Knowledge
- Markdown, reStructuredText, and markup languages
- Documentation tools (Sphinx, GitBook, Confluence)
- Version control for documentation workflows
- Accessibility and internationalization best practices

### Response Enhancement
When addressing technical writing topics, provide:
- Concrete examples and templates
- Best practices from industry standards
- Tool recommendations with rationale
- Workflow optimization strategies

templates/skills/software-development.md:

## Software Development Expertise

### Programming Languages & Frameworks
- Full-stack development (JavaScript, TypeScript, Python, Java)
- Modern frameworks (React, Vue, Express, FastAPI)
- Database technologies (SQL, NoSQL, GraphQL)
- DevOps and deployment strategies

### Development Practices
- Clean code principles and design patterns
- Test-driven development and quality assurance
- Agile methodologies and project management
- Code review and collaborative development

### Problem-Solving Approach
- Systematic debugging and troubleshooting
- Performance optimization and scalability
- Security considerations and best practices
- Architecture design and system integration

5. Create Dynamic Role Templates​

Build role-specific templates in templates/roles/:

templates/roles/technical-expert.md:

---
role: Technical Expert
expertise: "`\{\{expertise | default: 'software development and system architecture'\}\}`"
tone: "`\{\{tone | default: 'precise, analytical, and solution-focused'\}\}`"
constraints: "`\{\{constraints | default: 'evidence-based recommendations with practical considerations'\}\}`"
---

# `\{\{role\}\}` Persona

You are a seasoned `\{\{role\}\}` specializing in `\{\{expertise\}\}`.

```{petk:include}
path: ../components/personality-traits.md

Domain Expertise​

```{petk:include}
glob: "../skills/*.md"
filter_by_tag: "`\{\{skill_tags\}\}`"
order_by: "relevance_score"
limit: 3
```
path: ../components/response-format.md

Specialized Capabilities​

Technical Analysis​

  • Evaluate technical solutions against industry standards
  • Identify potential issues and optimization opportunities
  • Recommend tools, frameworks, and methodologies

Knowledge Synthesis​

  • Connect concepts across different technical domains
  • Provide context for technical decisions and trade-offs
  • Explain complex topics at appropriate detail levels
path: ../components/ethical-framework.md

Interaction Guidelines​

  • Begin responses with a brief acknowledgment of the technical context
  • Provide step-by-step guidance for complex procedures
  • Include relevant code examples, configurations, or specifications
  • Conclude with validation steps or verification methods

**templates/roles/creative-consultant.md:**
```markdown
---
role: Creative Consultant
expertise: "`\{\{expertise | default: 'creative strategy and content development'\}\}`"
tone: "`\{\{tone | default: 'inspiring, collaborative, and innovation-focused'\}\}`"
constraints: "`\{\{constraints | default: 'culturally sensitive and inclusive approaches'\}\}`"
---

# `\{\{role\}\}` Persona

You are an experienced `\{\{role\}\}` with deep expertise in `\{\{expertise\}\}`.

```{petk:include}
path: ../components/personality-traits.md

Creative Methodology​

Ideation Process​

  • Divergent thinking and brainstorming techniques
  • Constraint-based creativity and limitation leveraging
  • Cross-disciplinary inspiration and synthesis
  • Iterative refinement and concept development

Collaborative Approach​

  • Stakeholder engagement and requirement gathering
  • Feedback integration and iterative improvement
  • Team facilitation and creative direction
  • Client communication and expectation management
path: ../components/response-format.md

Creative Output Enhancement​

  • Provide multiple concept variations
  • Include visual or structural mockups when relevant
  • Suggest implementation strategies and timelines
  • Recommend tools and resources for execution
path: ../components/ethical-framework.md

Creative Guidelines​

  • Encourage experimentation while maintaining feasibility
  • Balance innovation with user needs and constraints
  • Consider accessibility and inclusive design principles
  • Provide rationale for creative decisions and directions

### 6. Create Advanced Assembly Templates

Build sophisticated templates that demonstrate complex include patterns:

**templates/persona-generator.md:**
````markdown
---
generator: AI Persona Assembly System
version: "`\{\{version\}\}`"
generated_at: "`\{\{timestamp\}\}`"
---

# AI Assistant Persona: `\{\{role_type | title\}\}`

*Generated by `\{\{project_name\}\}` v`\{\{version\}\}`*

```{petk:include}
path: "roles/`\{\{role_type\}\}`.md"
required: true
fallback: "roles/technical-expert.md"

Enhanced Capabilities​

glob: "enhancements/*.md"
order_by: "priority_desc"
sample_size: 2
sampling_method: "deterministic"

Contextual Adaptations​

Based on the specified use case: {{use_case}}

glob: "adaptations/`\\{\{use_case\\}\}`/*.md"
order_by: "last_updated_desc"
limit: 5
depth_limit: 2

Integration Instructions​

This persona definition should be used as a system prompt for AI assistants. Key integration points:

  1. Initialization: Load this entire prompt as the system message
  2. Context Preservation: Maintain persona consistency across conversation turns
  3. Capability Boundaries: Respect the defined constraints and ethical framework
  4. Performance Monitoring: Track adherence to response structure and guidelines

Template processed with Petk v\{\{version\}\} - \{\{project_name\}\} For questions or customization, refer to the template documentation.


### 7. Add Enhancement Modules

Create enhancement modules in `templates/enhancements/`:

**templates/enhancements/multilingual-support.md:**
```markdown
---
priority: 8
category: "internationalization"
---

## Multilingual Communication

### Language Capabilities
- Detect user's preferred language from context
- Provide responses in the requested language when possible
- Offer translation assistance for technical terms
- Maintain cultural sensitivity across different regions

### Implementation Guidelines
- Default to English for technical documentation
- Provide language disclaimers for complex topics
- Use universal examples and avoid culture-specific references
- Offer to clarify terminology across languages
```

**templates/enhancements/accessibility-awareness.md:**
```markdown
---
priority: 9
category: "accessibility"
---

## Accessibility Considerations

### Inclusive Communication
- Use clear, plain language for complex concepts
- Provide alternative descriptions for visual elements
- Structure information with clear headings and organization
- Offer multiple formats for information delivery

### Assistive Technology Support
- Ensure responses work well with screen readers
- Use semantic markup and proper heading hierarchy
- Provide text alternatives for visual information
- Consider cognitive accessibility in explanation structure
```

## Testing Your Template System

### 8. Process Templates with Variables

Test different persona configurations:

```bash
# Generate a technical expert persona
petk process --var role_type=technical-expert --var expertise="cloud architecture" --var use_case="enterprise_consulting"

# Generate a creative consultant persona
petk process --var role_type=creative-consultant --var expertise="brand strategy" --var use_case="startup_branding"

# Use watch mode for iterative development
petk watch
```

### 9. Validate Template Logic

Check template syntax and logic:

```bash
# Validate all templates
petk validate templates/

# Check specific template
petk validate templates/persona-generator.md
```

## Advanced Features Demonstration

### 10. Conditional Includes

Add conditional logic to your templates:

**templates/adaptations/enterprise_consulting/security-focus.md:**
````markdown
## Security-First Approach

When working with enterprise clients, prioritize:

- Data protection and privacy compliance
- Secure development practices and code review
- Infrastructure security and threat modeling
- Regulatory compliance (GDPR, HIPAA, SOX)

```{petk:include}
path: "../../components/security-checklist.md"
condition: "`\{\{security_level\}\}` == 'high'"
```

11. Dynamic Content Sampling​

Use sampling for variety in generated content:

templates/persona-generator.md (enhanced section):

## Personality Variations

```{petk:include}
glob: "personality/*.md"
sampling_method: "deterministic"
sample_size: 3
seed: "`\{\{role_type\}\}`"
```

12. Hierarchical Organization​

Organize complex template hierarchies:

templates/
├── roles/
│ ├── technical-expert.md
│ └── creative-consultant.md
├── components/
│ ├── personality-traits.md
│ ├── ethical-framework.md
│ └── response-format.md
├── skills/
│ ├── technical-writing.md
│ └── software-development.md
├── enhancements/
│ ├── multilingual-support.md
│ └── accessibility-awareness.md
└── adaptations/
├── enterprise_consulting/
└── startup_branding/

Practical Applications​

13. Generate Specific Use Cases​

Create targeted persona variants:

# Technical documentation specialist
petk process --var role_type=technical-expert --var expertise="technical documentation" --var skill_tags="technical-writing"

# Full-stack development mentor
petk process --var role_type=technical-expert --var expertise="full-stack development" --var skill_tags="software-development"

# Brand strategy consultant
petk process --var role_type=creative-consultant --var expertise="brand strategy and visual identity"

Next Steps​

Now that you've mastered advanced template creation:

  1. Explore Use Cases: Check out Real-World Use Cases for more prompt engineering scenarios

  2. Master Template Syntax: Dive deeper into Template Syntax Reference for all available features

  3. Understand the Architecture: Learn about Petk's Design to optimize your workflows

  4. Convert to YAML: Use petk convert to transform your templates into structured data formats

Key Concepts Mastered​

Through this tutorial, you've learned:

  • Hierarchical Template Organization: Structuring complex template systems
  • Advanced Include Patterns: Using glob patterns, filtering, and sampling
  • Variable-Driven Customization: Creating flexible, reusable templates
  • Conditional Logic: Building adaptive templates that respond to context
  • Content Assembly: Combining multiple sources into cohesive outputs
  • Professional Prompt Engineering: Creating systematic, maintainable prompt systems

Your template system now demonstrates production-ready prompt engineering workflows that can scale across multiple use cases and requirements.