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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@prism-lang/validator

v1.3.0

Published

Comprehensive validation toolkit for the Prism programming language

Readme

@prism-lang/validator

Comprehensive validation toolkit for the Prism programming language, designed to help LLMs and developers generate correct Prism patterns.

Features

  • Syntax Validation: Complete syntax checking with detailed error messages
  • Confidence Flow Analysis: Validates proper use of confidence operators and values
  • Type Checking: Runtime type validation for Prism expressions
  • Linting: Configurable rules to catch common mistakes and enforce best practices
  • LLM-Optimized Error Messages: Clear, actionable error messages with examples and fixes
  • Streaming Validation: Validate code as it's being generated

Installation

npm install @prism-lang/validator

Quick Start

import { createValidator } from '@prism-lang/validator';

const validator = createValidator();

// Validate Prism code
const code = `
const result = llm("Is this valid?")
uncertain if (~result > 0.7) {
  high { print("Very confident") }
  medium { print("Somewhat confident") }
  low { print("Not confident") }
}
`;

const result = validator.validateAll(code);
console.log(result.summary);

API Reference

PrismValidator

Basic syntax validation:

interface PrismValidator {
  validate(code: string): ValidationResult;
  parse(code: string): ParseResult;
}

ConfidenceChecker

Validates confidence flow and completeness:

interface ConfidenceChecker {
  checkConfidenceFlow(ast: ASTNode): ConfidenceFlowResult;
  checkConfidenceCompleteness(ast: ASTNode): ConfidenceCompletenessResult;
}

TypeChecker

Runtime type validation:

interface TypeChecker {
  checkTypes(ast: ASTNode): TypeCheckResult;
}

PrismLinter

Configurable linting rules:

interface PrismLinter {
  lint(code: string, config?: LinterConfig): LintResult[];
}

Unified Validator

Complete validation API:

const validator = createValidator({
  rules: {
    'no-infinite-loops': true,
    'confidence-range': true,
    'uncertain-completeness': true,
    'require-confidence-in-uncertain': true
  },
  maxConfidenceValue: 1,
  minConfidenceValue: 0
});

// Comprehensive validation
const result = validator.validateAll(code);

// Individual checks
const syntax = validator.validate(code);
const confidence = validator.checkConfidenceFlow(code);
const types = validator.checkTypes(code);
const lintResults = validator.lint(code);

// Streaming validation
validator.resetStreaming();
const chunk1 = validator.validateStreaming("const x = ");
const chunk2 = validator.validateStreaming("llm(");
const completions = validator.getStreamingCompletions(); // ["llm(\""]

Error Messages

The validator provides LLM-optimized error messages with:

  • Clear error codes for pattern matching
  • Specific fix suggestions
  • Working code examples
  • Contextual help

Example error format:

{
  "error": "CONFIDENCE_WITHOUT_VALUE",
  "line": 3,
  "column": 10,
  "message": "Variable 'result' uses confidence operator ~ but has no confidence value assigned",
  "fix": "Assign a confidence value using 'const result = value @ 0.8' or similar",
  "example": "const result = computeScore() @ 0.9\nconst confident = ~result"
}

Linting Rules

Available linting rules:

  • no-infinite-loops: Detect potentially infinite loops
  • confidence-range: Ensure confidence values are between 0 and 1
  • uncertain-completeness: Check uncertain statements have all branches
  • variable-declared-before-use: Enforce variable declaration before use
  • no-unused-variables: Detect unused variables
  • confidence-operator-usage: Validate proper use of confidence operators
  • no-constant-condition: Warn about constant conditions
  • no-unreachable-code: Detect unreachable code
  • consistent-confidence-usage: Ensure consistent confidence usage
  • require-confidence-in-uncertain: Require confidence in uncertain statements
  • no-empty-blocks: Warn about empty code blocks
  • no-duplicate-confidence-branches: Detect duplicate branch logic
  • prefer-confidence-operators: Suggest confidence operators when appropriate

Pattern Generation Support

The validator is specifically designed to help with automated pattern generation:

// Iterative pattern improvement
let pattern = generateInitialPattern();
let attempts = 0;

while (attempts < MAX_ATTEMPTS) {
  const validation = validator.validateAll(pattern);
  
  if (validation.valid) {
    break;
  }
  
  // Use formatted errors to improve the pattern
  const errors = validation.formattedErrors;
  pattern = improvePattern(pattern, errors);
  attempts++;
}

License

MIT