Skip to content

Commit bcdf2e7

Browse files
authored
Add CI build settings and README updates / PR 7
Add CI build settings and README updates
2 parents 3d5c1c9 + bd4eaa4 commit bcdf2e7

File tree

3 files changed

+83
-45
lines changed

3 files changed

+83
-45
lines changed

.github/workflows/ci.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build-test-lint:
11+
name: Build, Test, and Lint
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: 22
22+
cache: npm
23+
24+
- name: Install dependencies
25+
run: npm ci
26+
27+
- name: Build
28+
run: npm run build
29+
30+
- name: Run tests
31+
run: npm run test -- --run
32+
33+
# TODO: enable this once all checks are set
34+
# - name: Lint
35+
# run: npm run lint

README.md

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ A TypeScript framework for building safe and reliable AI systems with OpenAI Gua
55
## Installation
66

77
### Local Development
8+
89
Clone the repository and install locally:
910

1011
```bash
1112
# Clone the repository
1213
git clone https://github.com/openai/openai-guardrails-js.git
13-
cd guardrails-js
14+
cd openai-guardrails-js
1415

1516
# Install dependencies
1617
npm install
@@ -22,64 +23,61 @@ npm run build
2223
## Quick Start
2324

2425
### Drop-in OpenAI Replacement
26+
2527
The easiest way to use Guardrails TypeScript is as a drop-in replacement for the OpenAI client:
2628

2729
```typescript
2830
import { GuardrailsOpenAI } from '@openai/guardrails';
2931

3032
async function main() {
31-
// Use GuardrailsOpenAI instead of OpenAI
32-
const client = await GuardrailsOpenAI.create({
33-
version: 1,
34-
output: {
35-
version: 1,
36-
guardrails: [
37-
{"name": "Moderation", "config": {"categories": ["hate", "violence"]}}
38-
]
39-
}
33+
// Use GuardrailsOpenAI instead of OpenAI
34+
const client = await GuardrailsOpenAI.create({
35+
version: 1,
36+
output: {
37+
version: 1,
38+
guardrails: [{ name: 'Moderation', config: { categories: ['hate', 'violence'] } }],
39+
},
40+
});
41+
42+
try {
43+
const response = await client.responses.create({
44+
model: 'gpt-5',
45+
input: 'Hello world',
4046
});
41-
42-
try {
43-
const response = await client.responses.create({
44-
model: "gpt-5",
45-
input: "Hello world"
46-
});
47-
48-
// Access OpenAI response via .llm_response
49-
console.log(response.llm_response.output_text);
50-
51-
} catch (error) {
52-
if (error.constructor.name === 'GuardrailTripwireTriggered') {
53-
console.log(`Guardrail triggered: ${error.guardrailResult.info}`);
54-
}
47+
48+
// Access OpenAI response via .llm_response
49+
console.log(response.llm_response.output_text);
50+
} catch (error) {
51+
if (error.constructor.name === 'GuardrailTripwireTriggered') {
52+
console.log(`Guardrail triggered: ${error.guardrailResult.info}`);
5553
}
54+
}
5655
}
5756

5857
main();
5958
```
6059

6160
### Agents SDK Integration
61+
6262
```typescript
6363
import { GuardrailAgent } from '@openai/guardrails';
64-
import { Runner } from '@openai/agents';
64+
import { run } from '@openai/agents';
6565

6666
// Create agent with guardrails automatically configured
6767
const agent = new GuardrailAgent({
68-
config: {
69-
version: 1,
70-
output: {
71-
version: 1,
72-
guardrails: [
73-
{"name": "Moderation", "config": {"categories": ["hate", "violence"]}}
74-
]
75-
}
68+
config: {
69+
version: 1,
70+
output: {
71+
version: 1,
72+
guardrails: [{ name: 'Moderation', config: { categories: ['hate', 'violence'] } }],
7673
},
77-
name: "Customer support agent",
78-
instructions: "You are a helpful customer support agent."
74+
},
75+
name: 'Customer support agent',
76+
instructions: 'You are a helpful customer support agent.',
7977
});
8078

8179
// Use exactly like a regular Agent
82-
const result = await Runner.run(agent, "Hello, can you help me?");
80+
const result = await run(agent, 'Hello, can you help me?');
8381
```
8482

8583
## Evaluation Framework
@@ -89,12 +87,12 @@ The evaluation framework allows you to test guardrail performance on datasets an
8987
### Running Evaluations
9088

9189
**Using the CLI:**
90+
9291
```bash
9392
npm run build
9493
npm run eval -- --config-path src/evals/sample_eval_data/nsfw_config.json --dataset-path src/evals/sample_eval_data/nsfw_eval.jsonl
9594
```
9695

97-
9896
### Dataset Format
9997

10098
Datasets must be in JSONL format, with each line containing a JSON object:
@@ -116,16 +114,17 @@ Datasets must be in JSONL format, with each line containing a JSON object:
116114
import { GuardrailEval } from '@openai/guardrails';
117115

118116
const eval = new GuardrailEval(
119-
'configs/my_guardrails.json',
120-
'data/demo_data.jsonl',
121-
32, // batch size
122-
'results' // output directory
117+
'configs/my_guardrails.json',
118+
'data/demo_data.jsonl',
119+
32, // batch size
120+
'results' // output directory
123121
);
124122

125123
await eval.run('Evaluating my dataset');
126124
```
127125

128126
### Project Structure
127+
129128
- `src/` - TypeScript source code
130129
- `dist/` - Compiled JavaScript output
131130
- `src/checks/` - Built-in guardrail checks
@@ -146,6 +145,7 @@ The package includes comprehensive examples in the [`examples/` directory](https
146145
### Running Examples
147146

148147
#### Prerequisites
148+
149149
Before running examples, you need to build the package:
150150

151151
```bash
@@ -159,9 +159,11 @@ npm run build
159159
#### Running Individual Examples
160160

161161
**Using tsx (Recommended)**
162+
162163
```bash
163-
cd examples/basic
164-
npx tsx hello_world.ts # Basic chatbot with guardrails
164+
npx tsx examples/basic/hello_world.ts
165+
npx tsx examples/basic/streaming.ts
166+
npx tsx examples/basic/agents_sdk.ts
165167
```
166168

167169
## Available Guardrails
@@ -182,6 +184,6 @@ MIT License - see LICENSE file for details.
182184

183185
## Disclaimers
184186

185-
Please note that Guardrails may use Third-Party Services such as the [Presidio open-source framework](https://github.com/microsoft/presidio), 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: [platform.openai.com/guardrails](https://platform.openai.com/guardrails)
187+
Please note that Guardrails may use Third-Party Services such as the [Presidio open-source framework](https://github.com/microsoft/presidio), 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: [platform.openai.com/guardrails](https://platform.openai.com/guardrails)
186188

187-
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.
189+
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.

src/__tests__/unit/agents.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ describe('GuardrailAgent', () => {
241241
});
242242

243243
it('should handle guardrail execution errors based on raiseGuardrailErrors setting', async () => {
244+
process.env.OPENAI_API_KEY = 'test';
244245
const config = {
245246
version: 1,
246247
input: {

0 commit comments

Comments
 (0)