GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - openai/openai-guardrails-js: OpenAI Guardrails - TypeScript / JavaScript

BranchesTags
Open more actions menu

Latest commit

 

History

161 Commits
161 Commits

Folders and files

NameName
Last commit message
Last commit date
.agents/skills
.agents/skills
 
 
.changeset
.changeset
 
 
.github
.github
 
 
docs
docs
 
 
examples
examples
 
 
scripts
scripts
 
 
src
src
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
AGENTS.md
AGENTS.md
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
RELEASING.md
RELEASING.md
 
 
SECURITY.md
SECURITY.md
 
 
biome.json
biome.json
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
tsconfig.json
tsconfig.json
 
 
vercel.json
vercel.json
 
 
vitest.config.ts
vitest.config.ts
 
 

Repository files navigation

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-6-astra',
      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

  • Agents SDK: create an agent with await GuardrailAgent.create(...).
  • Azure OpenAI and local models.
  • Streaming and inspecting results without raising tripwires.

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

Use a Node.js version supported by the development toolchain.

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.

Contributing

Please share bug reports and feature requests through GitHub issues. Pull requests are limited to repository collaborators; we do not accept pull requests from non-collaborators. See CONTRIBUTING.md for the contribution policy and development guide. For security vulnerabilities, follow SECURITY.md.

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.

About

OpenAI Guardrails - TypeScript / JavaScript

guardrails.openai.com

Resources

Readme
MIT license

Contributing

Contributing

Security policy

Security policy
Activity
Custom properties

Stars

116 stars

Watchers

4 watching

Forks

22 forks
Report repository

Releases

Used by

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.