npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@promptforgee/core

v1.0.2

Published

Production-grade prompt engineering toolkit. Type-safe, composable, and extensible.

Downloads

547

Readme


Why this package exists

String concatenation is a fragile way to build AI prompts. It leads to hard-to-maintain code, context loss, and inconsistent formatting.

@promptforgee/core introduces a robust, builder-pattern API to programmatically construct, validate, and format prompts. By treating prompts as structured data rather than raw strings, you gain type safety, reusability, and guaranteed formatting that LLMs can parse reliably.

Features

  • Builder Pattern API: Construct prompts fluently step-by-step.
  • Structured State: Prompts are immutable objects, preventing accidental side effects.
  • Built-in Validation: Ensure your prompts have required contexts and constraints before sending them to an LLM.
  • Pluggable Formatters: Output your prompt as Markdown, XML, or JSON seamlessly.
  • Zero Dependencies: Extremely lightweight and fast.

Installation

# npm
npm install @promptforgee/core

# pnpm
pnpm add @promptforgee/core

# yarn
yarn add @promptforgee/core

# bun
bun add @promptforgee/core

Quick Start

import { Prompt, MarkdownFormatter, PromptValidator } from '@promptforgee/core';

// 1. Build the prompt
const myPrompt = Prompt.create()
  .role('Senior Systems Engineer')
  .task('Analyze the provided JSON payload and extract all user email addresses.')
  .context('The user is on a free tier subscription.')
  .constraint('Never output markdown formatting.')
  .output('A valid JSON array of strings.')
  .example('{"user": {"email": "[email protected]"}}', '["[email protected]"]');

// 2. Validate the prompt (optional but recommended)
const validation = myPrompt.validate(new PromptValidator());
if (!validation.isValid) {
  console.error('Prompt has issues:', validation.errors);
}

// 3. Format to string
const finalPromptString = myPrompt.build(new MarkdownFormatter());

console.log(finalPromptString);

API Overview

Prompt

The core builder class for creating structured prompts.

| Method | Description | | ------------------------- | -------------------------------------------------------------------- | | Prompt.create() | Initializes a new, empty Prompt instance. | | Prompt.fromState(state) | Rehydrates a Prompt instance from a serialized PromptState object. | | .role(text) | Sets the persona or role for the LLM to adopt. | | .task(text) | Sets the primary objective or task. | | .context(text) | Appends contextual information. Can be chained multiple times. | | .constraint(text) | Appends a strict rule or constraint. Can be chained. | | .output(format) | Sets the desired output schema/format. | | .language(lang) | Specifies the response language (e.g., "French"). | | .tone(tone) | Sets the tone of voice (e.g., "Professional"). | | .audience(target) | Defines the target audience for the output. | | .example(input, output) | Appends a few-shot example. | | .memory(text) | Sets conversation history/memory. | | .getState() | Returns the raw, serializable JSON state of the prompt. | | .validate(validator) | Validates the current state using a PromptValidator. | | .build(formatter) | Compiles the state into a string using a PromptFormatter. |

Formatters

  • MarkdownFormatter: Formats the prompt using clear Markdown headings (default).
  • (Additional formatters like XmlFormatter can be implemented by extending PromptFormatter)

Validation

  • PromptValidator: Evaluates the prompt state for minimum requirements (e.g., ensuring a task exists) and returns a ValidationResult.

Real-world Example

Building a dynamic prompt pipeline for an API endpoint:

import { Prompt } from '@promptforgee/core';

export async function generateEmailReply(userQuery: string, userTier: string) {
  const basePrompt = Prompt.create()
    .role('Customer Support Representative')
    .task("Write a polite email reply resolving the customer's query.")
    .constraint('Keep the response under 100 words.')
    .tone('Empathetic and helpful');

  // Dynamically inject context based on application state
  const contextualPrompt = basePrompt
    .context(`Customer query: ${userQuery}`)
    .context(`User tier: ${userTier}`);

  if (userTier === 'Enterprise') {
    return contextualPrompt
      .constraint('Offer a direct phone call with an account manager.')
      .build();
  }

  return contextualPrompt.build();
}

Ecosystem

@promptforgee/core is the engine that powers the entire PromptForge ecosystem.

@promptforgee/core (You are here) ↓ @promptforgee/analyzer (Analyzes core prompts) ↓ @promptforgee/optimizer (Optimizes core prompts) ↓ @promptforgee/registry (Stores core prompts)

Documentation

For full documentation and advanced usage, visit promptforge.dev/docs/core.

Examples

Check out our Examples directory for more real-world use cases.

Roadmap

  • 🚧 Built-in XML and JSON Formatters
  • 🚧 Token counting estimations
  • 🚧 Support for multimodal attachments (images/audio)

Contributing

We welcome contributions! Please read our Contributing Guide to get started.

License

MIT © Omnikon-Org