Promptfmt banner
codeaholicguy codeaholicguy

Promptfmt

Development community

Description

A composable prompt formatting library with runtime parameter substitution and conditional logic

Installation

This entry records only its repository, not the path inside it, so there is no exact command to give. Open the source below and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

README

promptfmt

A composable prompt formatting library with runtime parameter substitution and conditional logic.

Features

  • Component-based architecture: Build prompts from composable components (role, goal, input, output, context, persona, tone, few-shots, guardrails, constraints, tasks, steps)
  • Runtime parameter substitution: Use template strings with ${paramName} syntax
  • Conditional logic: Include/exclude components based on runtime conditions
  • Fluent API: Chain methods for intuitive prompt building
  • Type-safe: Full TypeScript support

Installation

npm install promptfmt

Quick Start

import { PromptBuilder, createCondition } from 'promptfmt';

const prompt = new PromptBuilder()
  .role('You are a wise numerology guide')
  .goal('Generate a numerology interpretation for ${userName}')
  .input({
    name: '${userName}',
    birthday: '${birthday}',
    numberType: '${numberType}',
    numberValue: '${numberValue}'
  })
  .persona((params) => {
    if (params.age > 10) {
      return 'The Steady Anchor persona';
    }
    return 'The Clear Mirror persona';
  })
  .output('Write ${maxSentences} sentences')
  .constraints('Do not include predictions')
  .build({ 
    userName: 'John',
    birthday: '1990-01-01',
    numberType: 'lifePath',
    numberValue: 5,
    age: 34,
    maxSentences: 10
  });

Component Types

Role

Defines the AI's role/identity.

builder.role('You are a helpful assistant');

Goal

Defines the objective of the prompt.

builder.goal('Answer user questions');

Input

Defines input data/parameters. Can accept strings or objects.

// String format
builder.input('Question: ${question}');

// Object format (auto-formatted with "- key: value")
builder.input({
  name: '${userName}',
  age: '${age}',
  metadata: { key: 'value' } // Non-string values are JSON.stringify'd
});
// Results in:
// "- name: John
// - age: 25
// - meta