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

@promptpack/langchain

v0.1.0

Published

LangChain.js integration for PromptPack - AI prompt management system

Readme

@promptpack/langchain

npm version License: MIT Quality Gate Status Coverage Maintainability Rating

LangChain.js integration for PromptPack - organize, version, and manage AI prompts with built-in governance and tools.

Features

  • 🎯 Prompt Registry - Load and manage PromptPacks from JSON/YAML
  • 🔧 Tool Integration - Built-in tool calling with governance policies
  • Validation - Response validation and guardrails
  • 🔄 LangChain Native - Seamless integration with LangChain templates
  • 📦 Type Safe - Full TypeScript support

Installation

npm install @promptpack/langchain

Peer Dependencies:

npm install @langchain/core langchain

Quick Start

1. Create a PromptPack

Create a JSON file customer-support.json:

{
  "$schema": "https://promptpack.org/schema/v1.0/promptpack.schema.json",
  "id": "customer-support",
  "name": "Customer Support Pack",
  "version": "1.0.0",
  "description": "Customer support prompts with multiple task types",
  "template_engine": {
    "version": "v1",
    "syntax": "{{variable}}"
  },
  "prompts": {
    "support": {
      "id": "support",
      "name": "Support Agent",
      "version": "1.0.0",
      "system_template": "You are a {{role}} for {{company}}. Help customers with their {{issue_type}} issues.",
      "variables": [
        {
          "name": "role",
          "type": "string",
          "required": true,
          "description": "The role of the assistant",
          "example": "helpful support agent"
        },
        {
          "name": "company",
          "type": "string",
          "required": true,
          "description": "Company name"
        },
        {
          "name": "issue_type",
          "type": "string",
          "required": false,
          "default": "general",
          "validation": {
            "enum": ["billing", "technical", "general"]
          }
        }
      ],
      "parameters": {
        "temperature": 0.7,
        "max_tokens": 1500
      }
    }
  }
}

2. Use with LangChain

import { PromptPackRegistry, PromptPackTemplate } from '@promptpack/langchain';
import { ChatOpenAI } from '@langchain/openai';

// Load the pack
const pack = PromptPackRegistry.loadFromFile('./customer-support.json');

// Create a template
const template = new PromptPackTemplate({
  pack,
  promptId: 'support',
});

// Use with LangChain
const model = new ChatOpenAI({ modelName: 'gpt-4' });
const chain = template.pipe(model);

// Invoke with variables
const response = await chain.invoke({
  role: 'helpful support agent',
  company: 'TechCorp',
  issue_type: 'billing',
});

console.log(response.content);

Documentation

Core Concepts

Registry

Load and manage PromptPacks:

import { PromptPackRegistry } from '@promptpack/langchain';

// Load from file
const pack = PromptPackRegistry.loadFromFile('./pack.json');

// Or from directory
const registry = PromptPackRegistry.fromDirectory('./packs');

// Get a specific prompt
const prompt = registry.getPrompt('pack-id', 'prompt-id');

See Core Concepts for details.

Templates

Use PromptPackTemplate with LangChain:

const template = new PromptPackTemplate({
  pack,
  promptId: 'support',
});

const chain = template.pipe(model);
const response = await chain.invoke({ role: 'agent', company: 'TechCorp' });

See Core Concepts for variables, validation, and advanced features.

Tools

Define tools at pack level with governance policies:

const tools = template.filterTools(allTools);
const model = new ChatOpenAI({ model: 'gpt-4o-mini' }).bindTools(tools);
const chain = template.pipe(model);

See Tools Documentation for governance, policies, and examples.

Validators

Validators work like tools - define them in your PromptPack, provide custom implementations:

import { OOTB_VALIDATORS, CustomValidatorFn } from '@promptpack/langchain';

// Custom validator implementations
const customValidators: Record<string, CustomValidatorFn> = {
  sentiment: (response, validator) => {
    // Your validation logic
    return { passed: true, validatorType: 'sentiment' };
  },
  pii_detection: (response, validator) => {
    // Your PII detection logic
    return { passed: true, validatorType: 'pii_detection' };
  },
};

// Create chain - validators come from pack definition
const chain = template
  .pipe(model)
  .pipe(template.createValidationRunnable(customValidators));

// Use with LangChain features
const result = await chain
  .withRetry({ stopAfterAttempt: 3 })
  .invoke(input);

Validator Types:

  • OOTB (always available): banned_words, max_length, min_length, regex_match
  • Custom (you provide): sentiment, pii_detection, toxicity, etc.

See Validators Documentation for complete guide.

Examples

The examples/ directory contains complete working examples:

  • examples/basic-usage.ts - Basic usage and JSON pack loading
  • examples/conversation.ts - Multi-turn conversations with memory
  • examples/integration.ts - LangChain features (streaming, batching, chaining)
  • examples/tools.ts - Tool calling with governance
  • examples/validation-native.ts - LangChain-native validation with .pipe(), .withRetry(), .withFallbacks()
  • examples/validation-error-test.ts - Missing validator error handling

Advanced Usage

For advanced features like model overrides, fragments, pipelines, and caching, see:

Contributing

Contributions welcome! See our contributing guidelines.

License

MIT

Links