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

llm-entropy-filter

v1.2.0

Published

Fast entropy and intent gate for LLM inputs (ALLOW/WARN/BLOCK). Reduces hallucinations, cost and spam before calling an LLM.

Readme

llm-entropy-filter

Deterministic linguistic entropy gate for LLM inputs.

llm-entropy-filter is a lightweight, configurable middleware that evaluates text using linguistic and logical entropy signals before it reaches an LLM.

It is not an AI model. It is a deterministic decision layer.

Why This Exists

Modern LLM systems face:

Spam floods

Phishing attempts

Fraud requests

Prompt injection

Manipulative urgency

Entropic noise

Most systems try to solve this reactively inside the model.

This project solves it before the model.

Order before generation. Criteria before probability.

Core Principles

Deterministic (no randomness)

Linguistic + logical analysis

Configurable via rulesets

Fully reproducible scoring

No external API calls

Middleware-ready

Architecture Overview Text ↓ Normalization ↓ Hard Triggers ↓ Topic Signals ↓ Entropy Scoring ↓ Policy Overrides ↓ Threshold Decision ↓ ALLOW | WARN | BLOCK

Installation npm install llm-entropy-filter

Quick Usage import { gate } from "llm-entropy-filter"; import ruleset from "./rulesets/public-api.js";

const result = gate("FREE prize winner click now claim $100!!!", { ruleset });

console.log(result);

Example output:

{ "action": "BLOCK", "entropy_score": 0.85, "flags": ["spam_sales", "money_signal", "shouting"], "intention": "marketing_spam", "confidence": 0.85 }

Actions Action Meaning ALLOW Low entropy, safe to process WARN Suspicious signals detected BLOCK High entropy or deterministic policy match Rulesets

Behavior is controlled entirely by rulesets.

Each ruleset defines:

thresholds

normalization

hard triggers

topic signals

policy overrides

Example:

{ "name": "public-api", "thresholds": { "warn": 0.4, "block": 0.6 }, "policy": { "block_flags": ["phishing_2fa_code"], "warn_flags": ["scam_wfh"] } }

Threshold Logic

Decision is score-based unless overridden by policy.

if score >= block → BLOCK else if score >= warn → WARN else → ALLOW

Policy Overrides (Deterministic Control Layer)

Rulesets may define deterministic overrides:

"policy": { "block_flags": ["phishing_2fa_code"], "warn_flags": ["fraud_payment_request"] }

Behavior:

If any block_flag matches → BLOCK (independent of score)

If any warn_flag matches → at least WARN

Otherwise → threshold decision

This allows:

Fraud cluster blocking

Linguistic certainty escalation

Safe tuning without lowering global thresholds

Logical Clusters

Entropy is not triggered by single words.

It increases when patterns accumulate.

Example combinations:

spam_kw_click + spam_kw_claim + spam_kw_free

urgency + fraud_payment_request

phishing_verify_threat + money_signal

Suspicion grows with structural density.

This reflects a linguistic-logical principle, not keyword matching alone.

Deterministic Stability Guarantee

For identical input + identical ruleset:

Output is deterministic

Score is reproducible

Flags are traceable

No external calls are made

This makes the gate:

Auditable

Compliance-friendly

Safe for logging

Open-Source Scope

This core version does NOT include:

Context memory

Session tracking

Behavioral anomaly detection

Identity verification

AI secondary review

Adaptive learning

Those belong to orchestration layers or enterprise systems.

This package focuses strictly on:

Linguistic entropy filtering.

Benchmarks

Run metrics:

npm run bench:metrics:public-api npm run bench:metrics:strict

Reports include:

Accuracy

Precision / Recall

F1 score

Confusion matrix

Per-tag accuracy

Overblock / Underblock rates

The system is fully reproducible.

Tuning Strategy

Do NOT blindly lower thresholds.

Prefer:

Add deterministic block_flags

Adjust pattern weights

Improve signal density

Then adjust thresholds if necessary

This preserves precision while increasing recall safely.

Middleware Mode

Typical production flow:

User Input ↓ Entropy Gate ↓ ALLOW → LLM WARN → Log / Rate-limit / Secondary review BLOCK → Reject

Philosophy

This project is grounded in a simple idea:

Entropy precedes manipulation.

Linguistic disorder precedes exploitation.

A gate should not think. It should filter.

Version

Current stable: v1.2.x

Features:

Deterministic entropy scoring

Policy override system

Configurable thresholds

Hard trigger architecture

Cluster-sensitive scoring

Zero BLOCK→ALLOW leaks in benchmark dataset

License

APACHE 2.0