Prompt template implementation using Handlebars

Provides variable substitution using Handlebars syntax with:

  • Built-in helpers (if, each, unless, with, etc.)
  • Custom helpers support
  • Partials support
  • Type validation
const template = new HandlebarsPromptTemplate({
id: 'greeting',
name: 'Greeting Template',
version: '1.0.0',
template: 'Hello {{userName}}! {{#if premium}}You are a premium user.{{/if}}',
variables: [
{ name: 'userName', type: 'string', required: true },
{ name: 'premium', type: 'boolean', required: false, default: false }
],
helpers: {
uppercase: (str: string) => str.toUpperCase()
}
});

const result = template.render({ userName: 'Alice', premium: true });
if (result.isSuccess) {
console.log(result.value); // "Hello Alice! You are a premium user."
}

Implements

  • PromptTemplate

Constructors

Methods

  • Render template with provided variables

    Parameters

    • variables: Record<string, unknown>

    Returns Result<string, Error>

  • Validate variables before rendering

    Parameters

    • variables: Record<string, unknown>

    Returns PromptValidationResult

Properties

id: string

Unique identifier for this prompt

name: string

Human-readable name

version: string

Semantic version

template: string

Template string with variable placeholders

variables: PromptVariable[]

Variable definitions

metadata: PromptMetadata

Metadata about this prompt