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

langpatrol

v0.1.7

Published

Developer SDK for pre-inference prompt validation and linting

Readme

LangPatrol

Developer SDK for pre-inference prompt validation and linting — think of it as ESLint or Prettier, but for prompts sent to large language models.

Installation

npm install langpatrol

Quick Start

import { analyzePrompt } from 'langpatrol';

const report = await analyzePrompt({
  prompt: 'Continue the list.',
  messages: [{ role: 'user', content: 'Continue the list.' }],
  model: 'gpt-5'
});

if (report.issues.length) {
  console.log('Issues found:', report.issues);
}

API

analyzePrompt(input: AnalyzeInput): Promise<Report>

Analyzes a prompt or message history and returns a report with issues and suggestions.

Input:

  • prompt?: string - Single prompt string
  • messages?: Msg[] - Chat message history
  • schema?: JSONSchema7 - Optional JSON schema
  • model?: string - Model name for token estimation
  • templateDialect?: 'handlebars' | 'jinja' | 'mustache' | 'ejs' - Template dialect
  • attachments?: Attachment[] - File attachments metadata
  • options?: { maxCostUSD?: number; maxInputTokens?: number; referenceHeads?: string[]; apiKey?: string; // API key for cloud API apiBaseUrl?: string; // Base URL for cloud API (default: 'http://localhost:3000') check_context?: { // Domain context checking (cloud-only, requires apiKey and AI Analytics subscription) domains: string[]; // List of domain keywords/topics to validate the prompt against }; }

Output:

  • issues: Issue[] - Detected issues
  • suggestions: Suggestion[] - Suggested fixes
  • cost?: { estInputTokens: number; estUSD?: number } - Cost estimates
  • meta?: { latencyMs: number; modelHint?: string } - Metadata

optimizePrompt(input: OptimizeInput): Promise<OptimizeResponse>

Optimizes (compresses) a user prompt to help reduce token usage. This is a cloud-only feature and requires an API key.

Input:

  • prompt: string - The prompt text to optimize
  • model?: string - Optional target model name
  • options?: { apiKey: string; // Required: cloud API key apiBaseUrl?: string; // Optional: base URL for cloud API (default: 'http://localhost:3000') }

Output:

  • optimized_prompt: string - Optimized prompt text
  • ratio: string - Compression ratio (e.g., "33.00%")
  • origin_tokens: number - Original token count
  • optimized_tokens: number - Optimized token count

Example:

import { optimizePrompt } from 'langpatrol';

const optimized = await optimizePrompt({
  prompt: 'Write a detailed project proposal for building a new mobile app...',
  model: 'gpt-4',
  options: {
    apiKey: process.env.LANGPATROL_API_KEY!,
    apiBaseUrl: 'https://api.langpatrol.com' // optional override
  }
});

console.log('Compressed prompt:', optimized.compressed);
console.log('Ratio:', optimized.ratio);
console.log('Tokens:', optimized.origin_tokens, '->', optimized.optimized_tokens);

Issue Codes

  • MISSING_PLACEHOLDER - Unresolved template variables
  • MISSING_REFERENCE - Deictic references without context
  • CONFLICTING_INSTRUCTION - Contradictory directives
  • SCHEMA_RISK - JSON schema mismatches
  • INVALID_SCHEMA - Invalid JSON Schema structure
  • TOKEN_OVERAGE - Token limits exceeded
  • OUT_OF_CONTEXT - Prompt doesn't match specified domain activity (cloud-only, requires check_context option)

Examples

Vercel AI SDK

import { analyzePrompt } from 'langpatrol';

export async function guardedCall(messages, model) {
  const report = await analyzePrompt({ messages, model });
  
  if (report.issues.find(i => i.code === 'TOKEN_OVERAGE')) {
    // Summarize or trim, then proceed
  }
  
  // Then call your model
}

Domain Context Checking (Cloud-only)

Validate that prompts match your domain activity using the check_context option. This feature requires an API key and AI Analytics subscription.

import { analyzePrompt } from 'langpatrol';

const report = await analyzePrompt({
  prompt: 'Generate a marketing email for our SaaS product',
  model: 'gpt-4',
  options: {
    apiKey: 'your-api-key',
    check_context: {
      domains: ['saas', 'marketing', 'email', 'software'] // Domain keywords/topics
    }
  }
});

if (report.issues.find(i => i.code === 'OUT_OF_CONTEXT')) {
  console.warn('Prompt is out of context for your domain');
  // Handle out-of-context prompt
}

Note: The check_context option:

  • Requires an apiKey to be provided
  • Automatically routes to the /api/v1/ai-analytics endpoint
  • Returns a high-severity OUT_OF_CONTEXT error when the prompt doesn't match the specified domains
  • Requires an AI Analytics subscription on the cloud API

License

MIT License