
Research
2025 Report: Destructive Malware in Open Source Packages
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.
@openai/guardrails
Advanced tools
OpenAI Guardrails: A TypeScript framework for building safe and reliable AI systems
This is the TypeScript version of OpenAI Guardrails, a package for adding configurable safety and compliance guardrails to LLM applications. It provides a drop-in wrapper for OpenAI's TypeScript / JavaScript client, enabling automatic input/output validation and moderation using a wide range of guardrails.
Most users can simply follow the guided configuration and installation instructions at guardrails.openai.com.
Follow the configuration and installation instructions at guardrails.openai.com.
Clone the repository and install locally:
# Clone the repository
git clone https://github.com/openai/openai-guardrails-js.git
cd openai-guardrails-js
# Install dependencies
npm install
# Build the package
npm run build
The easiest way to use Guardrails TypeScript is as a drop-in replacement for the OpenAI client:
import { GuardrailsOpenAI } from '@openai/guardrails';
async function main() {
// Use GuardrailsOpenAI instead of OpenAI
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',
});
// Access OpenAI response directly
console.log(response.output_text);
} catch (error) {
if (error.constructor.name === 'GuardrailTripwireTriggered') {
console.log(`Guardrail triggered: ${error.guardrailResult.info}`);
}
}
}
main();
import { GuardrailAgent } from '@openai/guardrails';
import { run } from '@openai/agents';
// Create agent with guardrails automatically configured
const agent = new GuardrailAgent({
config: {
version: 1,
output: {
version: 1,
guardrails: [{ name: 'Moderation', config: { categories: ['hate', 'violence'] } }],
},
},
name: 'Customer support agent',
instructions: 'You are a helpful customer support agent.',
});
// Use exactly like a regular Agent
const result = await run(agent, 'Hello, can you help me?');
The evaluation framework allows you to test guardrail performance on datasets and measure metrics like precision, recall, and F1 scores.
Using the CLI:
npm run build
npm run eval -- --config-path src/evals/sample_eval_data/nsfw_config.json --dataset-path src/evals/sample_eval_data/nsfw_eval.jsonl
Datasets must be in JSONL format, with each line containing a JSON object:
{
"id": "sample_1",
"data": "Text to evaluate",
"expectedTriggers": {
"guardrail_name_1": true,
"guardrail_name_2": false
}
}
import { GuardrailEval } from '@openai/guardrails';
const eval = new GuardrailEval(
'configs/my_guardrails.json',
'data/demo_data.jsonl',
32, // batch size
'results' // output directory
);
await eval.run('Evaluating my dataset');
src/ - TypeScript source codedist/ - Compiled JavaScript outputsrc/checks/ - Built-in guardrail checkssrc/evals/ - Evaluation frameworkexamples/ - Example usage and sample dataThe package includes comprehensive examples in the examples/ directory:
agents_sdk.ts: Agents SDK integration with GuardrailAgenthello_world.ts: Basic chatbot with guardrails using GuardrailsOpenAIazure_example.ts: Azure OpenAI integration examplelocal_model.ts: Using local models with guardrailsstreaming.ts: Streaming responses with guardrailssuppress_tripwire.ts: Handling guardrail violations gracefullyBefore running examples, you need to build the package:
# Install dependencies (if not already done)
npm install
# Build the TypeScript code
npm run build
Using tsx (Recommended)
npx tsx examples/basic/hello_world.ts
npx tsx examples/basic/streaming.ts
npx tsx examples/basic/agents_sdk.ts
The TypeScript implementation includes the following built-in guardrails:
MIT License - see LICENSE file for details.
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.
FAQs
OpenAI Guardrails: A TypeScript framework for building safe and reliable AI systems
The npm package @openai/guardrails receives a total of 4,474 weekly downloads. As such, @openai/guardrails popularity was classified as popular.
We found that @openai/guardrails demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 12 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.

Research
/Security News
A five-month operation turned 27 npm packages into durable hosting for browser-run lures that mimic document-sharing portals and Microsoft sign-in, targeting 25 organizations across manufacturing, industrial automation, plastics, and healthcare for credential theft.