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

factlite

v1.1.0

Published

A lightweight framework for fact-checking AI-generated content.

Downloads

34

Readme

FactLite 🪶

English | 中文

Give Your LLM a "System 2" Brain with a Simple Higher-Order Function.

npm version License: MIT Node.js 18+


In the last mile of deploying Generative AI, hallucination is the final boss. Heavy frameworks introduce too much boilerplate and complexity, while raw API calls offer no safety net.

FactLite is a production-ready, feather-light Node.js micro-framework designed to solve this exact problem. It enhances your existing LLM calls with an automated, self-correcting evaluation loop, inspired by the top-tier Agentic "Reflexion" Architecture, without forcing you to refactor your codebase.

🚀 Key Features

  • ✨ Zero-Intrusion: Add fact-checking and self-correction to any async function with a simple verify() higher-order function wrapper. No need to rewrite your existing logic.
  • ⚡️ Async-Native: Built from the ground up to support async/await, making it perfect for high-performance Node.js backends like Express, Fastify, or Koa.
  • 🤖 Agentic Workflow: Implements an automated Generate -> Evaluate -> Reflect loop. Your LLM is forced to critique and iteratively improve its own answers until they meet your quality standards.
  • 🧩 Extensible & Pluggable:
    • Bring your own judge! Use the built-in LLMJudge or create your own validation logic (e.g., regex, database lookups, type checks) with CustomJudge.
    • Define your own failure policies. Raise an error, return a safe message, or implement custom logic with FallbackAction.
  • 🌐 Framework Agnostic: FactLite doesn't care how you call your LLM. Whether you're using the openai SDK, anthropic's client, or a simple fetch call to a local model, as long as it's an async function that returns a string, FactLite can safeguard it.

📦 Installation

npm install "git+https://github.com/SRInternet-Studio/FactLite.git#nodejs-package"

🎯 Quick Start: The "Aha!" Moment

See how easy it is to upgrade your existing code from a simple API call to a self-correcting agent.

Before: A standard, unprotected LLM call.

import OpenAI from "openai";

const client = new OpenAI({ apiKey: "your-key" });

async function askAI(question) {
  const response = await client.chat.completions.create({
    model: "gpt-3.5-turbo",
    messages: [{ role: "user", content: question }],
  });
  return response.choices[0].message.content;
}

// This might return a factually incorrect answer, and you'd never know.
console.log(await askAI("Was Li Bai an emperor in the Song Dynasty?"));

After: Protected by FactLite with a simple wrapper.

import OpenAI from "openai";
import { verify, rules, actions } from "factlite";

const client = new OpenAI({ apiKey: "your-key" });

// Configure a powerful judge
const config = verify.config({
  rule: new rules.LLMJudge({ model: "gpt-4o-mini", apiKey: "your-key" }),
  maxRetries: 1,
});

// Wrap your function with verify
const askAI = verify({ config })(async function (question) {
  const response = await client.chat.completions.create({
    model: "gpt-3.5-turbo",
    messages: [{ role: "user", content: question }],
  });
  return response.choices[0].message.content;
});

// Now, the function will automatically correct itself before returning.
console.log(await askAI("Was Li Bai an emperor in the Song Dynasty?"));

What you'll see in your console:

10:30:05 - [FactLite] - Generating initial answer...
10:30:08 - [FactLite] - Evaluating answer quality...
10:30:12 - [FactLite] - ❌ Hallucination or error detected: The answer incorrectly states that Li Bai was related to the Song Dynasty. He was a poet from the Tang Dynasty.
10:30:12 - [FactLite] - Triggering reflection and rewrite, attempt 1...
10:30:16 - [FactLite] - Evaluating answer quality...
10:30:19 - [FactLite] - ✅ Correction successful, returning the verified answer!

No, Li Bai was not an emperor in the Song Dynasty. He was a renowned poet who lived during the Tang Dynasty (701-762 AD).

💡 Advanced Usage

Custom Rules (CustomJudge)

Go beyond LLM-based checks. Enforce any local business logic you can imagine.

function companyPolicyJudge(prompt, answer) {
  // Rule 1: No short answers
  if (answer.length < 50) {
    return { is_pass: false, feedback: "Answer is too short. Please be more detailed." };
  }
  // Rule 2: Don't mention competitors
  if (answer.includes("Google")) {
    return { is_pass: false, feedback: "Do not mention competitor names." };
  }
  return { is_pass: true, feedback: "" };
}

const askSupportBot = verify({
  rule: new rules.CustomJudge(companyPolicyJudge),
})(async function (prompt) {
  // ... your LLM call
});

Web-Enhanced Verification (Web_LLMJudge)

Leverage web search to verify answers against the latest information, perfect for time-sensitive or rapidly evolving topics.

const askAboutCurrentEvents = verify({
  rule: new rules.Web_LLMJudge({
    model: "gpt-4o-mini",
    maxResults: 3,      // Number of search results to use
    apiKey: "your-key",
  }),
})(async function (question) {
  // ... your LLM call
});

Web_LLMJudge Options:

  • model: The OpenAI model to use for evaluation
  • maxResults: Number of search results to incorporate (default: 3)
  • apiKey: Optional OpenAI API key
  • baseURL: Optional OpenAI API base URL

Custom Failure Actions (FallbackAction)

Decide exactly what happens when an answer fails all retries.

import { actions } from "factlite";

const askSensitiveQuestion = verify({
  rule: new rules.LLMJudge({ model: "gpt-4o-mini", apiKey: "your-key" }),
  onFail: new actions.ReturnSafeMessage(
    "I'm sorry, I cannot provide a confident answer to that question at the moment."
  ),
})(async function (question) {
  // ... your LLM call
});

const askCriticalQuestion = verify({
  rule: new rules.LLMJudge({ model: "gpt-4o-mini", apiKey: "your-key" }),
  onFail: new actions.RaiseError(),
})(async function (question) {
  // ... your LLM call
});

Using Config Object

Group your configuration into a reusable Config object:

const config = verify.config({
  rule: new rules.LLMJudge({ model: "gpt-4o-mini", apiKey: "your-key" }),
  maxRetries: 2,
  onFail: new actions.ReturnBest(),
});

const fn1 = verify({ config })(async (q) => { /* ... */ });
const fn2 = verify({ config })(async (q) => { /* ... */ });

🛠️ How It Works

FactLite's verify() higher-order function wraps your async function in a simple yet powerful control loop:

  1. Generate: Your original function is called to produce an initial draft.
  2. Evaluate: The configured rule (e.g., LLMJudge) is invoked to assess the draft.
  3. Reflect & Retry:
    • If the evaluation passes, the answer is returned to the caller.
    • If it fails, the feedback is combined with the original prompt to create a "reflection prompt," forcing the LLM to correct its mistake. The process repeats from Step 1 until maxRetries is reached.
  4. Fallback: If all retries fail, the configured onFail action is executed.

🤝 Contributing

Contributions are welcome! Whether it's a new rule, a new fallback action, or a performance improvement, feel free to open an issue or submit a pull request.

The cover design for this project was supported by @apanzinc.

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.