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

node-ai-guard

v1.0.0

Published

A lightweight TypeScript/Node.js safety layer for AI Agents. Secure your APIs against LLM hallucinations and excessive agency using Zod-powered guardrails

Downloads

9

Readme

🛡️ node-ai-guard

The safety layer for AI Agents. Validate, sanitize, and govern AI-generated intents before they hit your production APIs.

npm version License: MIT TypeScript

The Problem: AI Hallucinations & Excessive Agency

Large Language Models (LLMs) are great at calling tools, but they are unpredictable. When you give an AI Agent access to your APIs (Stripe, Slack, Database), you face critical risks:

  1. Hallucinations: The AI sends parameters that don't exist or are formatted incorrectly.
  2. Excessive Agency: The AI tries to refund $10,000 instead of $10 because it misread the prompt.
  3. Security Risks: A user tricks your AI into executing destructive commands via prompt injection.

node-ai-guard provides a Zod-powered guardrail wrapper designed specifically for AI-generated JSON payloads. It ensures every action is structurally sound and follows strict business safety rules.


🚀 Installation

npm install node-ai-guard zod

🛠️ Quick Start

Define a Guard with a schema and custom safety rules. If the AI violates a rule, the guard returns a clear error that you can feed back to the AI for self-correction.

import { createGuard } from 'node-ai-guard';
import { z } from 'zod';

// 1. Define your safety guard
const refundGuard = createGuard({
  name: "process_refund",
  description: "Used to issue a refund to a customer.",
  schema: z.object({
    orderId: z.string(),
    amount: z.number(),
    reason: z.string()
  }),
  // Hard safety rules the AI cannot bypass
  rules: [
    {
      check: (data) => data.amount <= 100,
      message: "Refunds over $100 require manual manager intervention."
    }
  ]
});

// 2. Validate the AI's intent (e.g., from an LLM tool call)
const aiIntent = { orderId: "ORD-99", amount: 500, reason: "Defective" };

const result = await refundGuard.validate(aiIntent);

if (!result.success) {
  console.log("🚫 Action Blocked:", result.error); 
  // Output: "Refunds over $100 require manual manager intervention."
}

✨ Key Features

  • Type-Safe Validation: Full TypeScript support with Zod integration.
  • 🛡️ Business Rule Engine: Go beyond data types. Set custom logic for risk scores and safety limits.
  • 🤖 AI Self-Correction: Returns detailed error messages designed to help LLMs realize their mistake and retry.
  • 📦 Lightweight & Fast: Zero bloat, optimized for high-throughput Node.js environments like Express or AWS Lambda.
  • 📜 Audit Trail Ready: Easily logs attempts to MongoDB or PostgreSQL for compliance and debugging.

🗺️ Roadmap (Phase 1 & 2)

  • [x] Core Zod Wrapper
  • [x] Custom Safety Rules Engine
  • [ ] Middleware Support: First-class support for Express.js and Fastify.
  • [ ] Human-in-the-Loop: Built-in hooks for Slack/Discord "Approve/Deny" buttons.
  • [ ] Tool Definition Generator: Automatically export OpenAI-compatible JSON tool definitions from your guards.

🤝 Contributing

This is an early-stage project built to solve AI trust issues. If you have ideas for safety patterns (Human-in-the-loop, rate limiting for agents, etc.), feel free to open an issue!

📄 License

MIT © [josephallwin1996]