Template for generating prompts with variable substitution

Provides a structured way to manage prompt templates with:

  • Variable substitution
  • Type validation
  • Versioning
  • Metadata
const template: PromptTemplate = {
id: 'customer-support-greeting',
name: 'Customer Support Greeting',
version: '1.0.0',
template: 'Hello {{userName}}, how can I help you with {{topic}} today?',
variables: [
{ name: 'userName', type: 'string', required: true },
{ name: 'topic', type: 'string', required: true }
],
metadata: {
description: 'Friendly greeting for customer support',
tags: ['support', 'greeting'],
createdAt: new Date(),
updatedAt: new Date()
},
render: (vars) => {...},
validate: (vars) => {...}
};

const result = template.render({ userName: 'Alice', topic: 'billing' });
// "Hello Alice, how can I help you with billing today?"
interface PromptTemplate {
    id: string;
    name: string;
    version: string;
    template: string;
    variables: PromptVariable[];
    metadata: PromptMetadata;
    render(variables: Record<string, unknown>): Result<string, Error>;
    validate(variables: Record<string, unknown>): PromptValidationResult;
}

Methods

  • Render template with provided variables

    Parameters

    • variables: Record<string, unknown>

      Variable values to substitute

    Returns Result<string, Error>

    Rendered prompt string

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