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

@hazeljs/guardrails

v1.0.5

Published

Content safety, PII handling, and output validation for HazelJS AI applications

Readme

@hazeljs/guardrails

Content safety, PII handling, and output validation for HazelJS AI applications.

npm version npm downloads License: Apache-2.0

Why Guardrails?

AI applications face unique security challenges: prompt injection, PII leakage, toxic output. Unlike LangChain or Vercel AI SDK, HazelJS provides built-in guardrails that plug into HTTP, AI, and agent layers—no separate middleware.

Features

  • PII Detection & Redaction — Email, phone, SSN, credit card (configurable entities)
  • Prompt Injection Detection — Heuristic patterns (e.g. "ignore previous instructions", "jailbreak")
  • Toxicity Check — Keyword blocklist for harmful content
  • Output Validation — Schema validation and PII redaction on LLM responses
  • HTTP Integration — GuardrailPipe and GuardrailInterceptor for routes
  • AI Integration — @GuardrailInput and @GuardrailOutput decorators for @AITask
  • Agent Integration — Automatic input/output guardrails for @hazeljs/agent tools

Installation

npm install @hazeljs/guardrails

Or with the HazelJS CLI:

hazel add guardrails

Quick Start

1. Import the Module

import { HazelModule } from '@hazeljs/core';
import { GuardrailsModule } from '@hazeljs/guardrails';

@HazelModule({
  imports: [
    GuardrailsModule.forRoot({
      redactPIIByDefault: true,
      blockInjectionByDefault: true,
      blockToxicityByDefault: true,
    }),
  ],
})
export class AppModule {}

2. Use with HTTP Routes

GuardrailPipe — Validate request body:

import { Controller, Post, Body, UsePipes } from '@hazeljs/core';
import { GuardrailPipe } from '@hazeljs/guardrails';

@Controller({ path: '/chat' })
export class ChatController {
  @Post()
  @UsePipes(GuardrailPipe)
  async chat(@Body() body: { message: string }) {
    return { reply: '...' };
  }
}

GuardrailInterceptor — Validate input and output:

import { Controller, UseInterceptors } from '@hazeljs/core';
import { GuardrailInterceptor } from '@hazeljs/guardrails';

@Controller({ path: '/chat' })
@UseInterceptors(GuardrailInterceptor)
export class ChatController {
  @Post()
  async chat(@Body() body: { message: string }) {
    return { reply: '...' };
  }
}

3. Use with @AITask

import { Controller, Post, Body } from '@hazeljs/core';
import { AIEnhancedService, AITask } from '@hazeljs/ai';
import { GuardrailsService, GuardrailInput, GuardrailOutput } from '@hazeljs/guardrails';

@Controller({ path: '/chat' })
export class ChatController {
  constructor(
    public aiService: AIEnhancedService,
    private guardrailsService: GuardrailsService
  ) {}

  @GuardrailInput()
  @GuardrailOutput()
  @AITask({ provider: 'openai', model: 'gpt-4' })
  @Post()
  async chat(@Body() body: { message: string }) {
    return body.message;
  }
}

4. Use with @hazeljs/agent

When both GuardrailsModule and AgentModule are imported, tool input and output are automatically validated:

@HazelModule({
  imports: [GuardrailsModule.forRoot(), AgentModule.forRoot()],
})
export class AppModule {}

Configuration

| Option | Type | Default | Description | | ------------------------- | ----------------- | --------------------------------------- | --------------------------------- | | piiEntities | PIIEntityType[] | ['email','phone','ssn','credit_card'] | Entities to detect/redact | | redactPIIByDefault | boolean | false | Redact PII in input by default | | blockInjectionByDefault | boolean | true | Block prompt injection by default | | blockToxicityByDefault | boolean | true | Block toxic content by default | | injectionBlocklist | string[] | — | Custom injection patterns | | toxicityBlocklist | string[] | — | Custom toxicity keywords |

API

GuardrailsService

  • checkInput(input, options?) — Validate input, returns { allowed, modified?, violations? }
  • checkOutput(output, options?) — Validate output, returns { allowed, modified?, violations? }
  • redactPII(text, entities?) — Redact PII from text

GuardrailViolationError

Thrown when content is blocked. Includes violations and blockedReason. Use an Exception Filter to map to HTTP 400.

Use Cases

  • Customer support chatbot — Block injection, redact PII, validate responses
  • Internal AI tools — Ensure agent tools don't leak sensitive data
  • Public chat API — GuardrailPipe on /chat to reject toxic or injection attempts
  • Compliance — PII redaction for GDPR/CCPA, documented controls for audits

Learn More