-
Notifications
You must be signed in to change notification settings - Fork 6
Labels
bugSomething isn't workingSomething isn't working
Description
Summary
The runGuardrails function from @openai/guardrails ignores the OpenAI client provided in the context.guardrailLlm parameter and instead tries to create its own client using the OPENAI_API_KEY environment variable.
Environment
- Package:
@openai/guardrailsVersion: 0.1.2(latest) - Node.js version: v22.17.0
- Operating System: macOS
Expected Behavior
When calling runGuardrails(text, config, context, raiseGuardrailErrors) with a context object containing guardrailLlm (an initialized OpenAI client), the function should use that client for all OpenAI API calls.
Actual Behavior
The function ignores the provided context.guardrailLlm client and attempts to create its own OpenAI client, which fails when OPENAI_API_KEY environment variable is not set.
Minimal Reproduction Example
const { OpenAI } = require('openai');
const { runGuardrails } = require('@openai/guardrails');
const client = new OpenAI({
apiKey: 'sk-xxx'
});
const guardrailsConfig = {
guardrails: [
{
name: 'Moderation',
config: {
categories: ['sexual/minors']
}
}
]
};
const context = {
guardrailLlm: client
};
const testText = 'Hello, this is a test message for guardrails.';
runGuardrails(testText, guardrailsConfig, context, true).then(output => {
console.log('runGuardrails completed successfully');
}).catch(error => {
console.error(error);
// ❌ ERROR: The OPENAI_API_KEY environment variable is missing or empty; either provide it, or instantiate the OpenAI client with an apiKey option, like new OpenAI({ apiKey: 'My API Key' }).
});Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working