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

@openai/guardrails

v0.3.0

Published

OpenAI Guardrails: A TypeScript framework for building safe and reliable AI systems

Readme

OpenAI Guardrails: TypeScript (Preview)

Add configurable input and output checks to your OpenAI applications. Guardrails wraps the OpenAI JavaScript/TypeScript client and supports responses.create() and chat.completions.create(), with integrations for Azure OpenAI and the Agents SDK.

Documentation · Configuration wizard · Examples · Migration guide

OpenAI Guardrails configuration screenshot

Quickstart

Requires Node.js 22.13+ on the 22.x release line, or Node.js 24+. Set OPENAI_API_KEY in your environment, then install:

npm install @openai/guardrails

Save this as guardrails-example.ts. It checks generated text for the selected moderation categories before returning it:

import { GuardrailsOpenAI, GuardrailTripwireTriggered } from '@openai/guardrails';

async function main() {
  const client = await GuardrailsOpenAI.create({
    version: 1,
    output: {
      version: 1,
      guardrails: [{ name: 'Moderation', config: { categories: ['hate', 'violence'] } }],
    },
  });

  try {
    const response = await client.responses.create({
      model: 'gpt-5',
      input: 'Hello world',
    });
    console.log(response.output_text);
  } catch (error) {
    if (error instanceof GuardrailTripwireTriggered) {
      console.log('Response blocked by a guardrail.');
    } else {
      throw error;
    }
  }
}

main().catch(() => {
  console.error('Request failed. Check your API credentials and configuration.');
  process.exitCode = 1;
});

Run it with:

npx tsx guardrails-example.ts

You can also pass an exported configuration file path to GuardrailsOpenAI.create(). Use the configuration wizard to choose checks and the quickstart guide to learn about preflight, input, and output stages. See tripwire handling for handling blocked requests and guardrail execution errors.

Integrations and checks

Built-in checks include Moderation, Contains PII, URL Filter, Hallucination Detection, Jailbreak, Prompt Injection Detection, Off Topic Prompts, and Custom Prompt Check. Each reference explains its configuration and prerequisites.

Evaluations

Measure guardrail precision, recall, and F1 against labeled datasets. Export a configuration as guardrails_config.json from the wizard and create data.jsonl with one JSON object per line. Labels must match the guardrail names in your configuration; for a Moderation-only configuration:

{"id":"sample_1","data":"Hello world","expected_triggers":{"Moderation":false}}

Run the installed CLI:

npx --no-install guardrails eval --config-path guardrails_config.json --dataset-path data.jsonl

See the evaluation guide for dataset requirements, benchmarking, and multi-turn evaluation, or the programmatic API.

Local development

git clone https://github.com/openai/openai-guardrails-js.git
cd openai-guardrails-js
npm ci
npm run build
npm run test:run
npm run lint
npm run docs:check

With OPENAI_API_KEY set, run a repository example:

npx tsx examples/basic/hello_world.ts

See the examples guide for more examples and their prerequisites, and the release guide for publishing.

License

MIT.

Disclaimers

Please note that Guardrails may use Third-Party Services such as the Presidio open-source framework, which are subject to their own terms and conditions and are not developed or verified by OpenAI. For more information on configuring guardrails, please visit: guardrails.openai.com

Developers are responsible for implementing appropriate safeguards to prevent storage or misuse of sensitive or prohibited content (including but not limited to personal data, child sexual abuse material, or other illegal content). OpenAI disclaims liability for any logging or retention of such content by developers. Developers must ensure their systems comply with all applicable data protection and content safety laws, and should avoid persisting any blocked content generated or intercepted by Guardrails. Guardrails calls paid OpenAI APIs, and developers are responsible for associated charges.