Skip to content

Conversation

@steven10a
Copy link
Collaborator

@steven10a steven10a commented Nov 3, 2025

Fixes reported [BUG]

  • User reports they are still getting an error when using the moderation guardrail and passing in the apiKey
  • The instanceof check confirming the guardrailLlm is an OpenAI client is fragile and can fail under different resolution paths or uses. This check was removed as it is not needed, we test for the moderation endpoint directly, falling back to creating a new client with env vars if the endpoint doesn't exit.
  • It is believed the user was seeing this error as they were using the underlying runGuardrails method rather than using the Guardrails client.

Note: The current fallback is not a very robust way to handle the base client not being an OpenAI client. A PR should follow that allows the user to set an OpenAI api key for guardrails that require them.

@steven10a steven10a requested review from Copilot and gabor-openai and removed request for Copilot November 3, 2025 17:35
@steven10a steven10a changed the title Properly pass back execution errors More robust handling of checking guardrailLlm client type Nov 3, 2025
@steven10a steven10a requested a review from Copilot November 3, 2025 17:47
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the moderation guardrail error handling to use the executionFailed flag instead of throwing exceptions or returning custom error messages. This change standardizes error handling by delegating error-propagation decisions to the runGuardrails function via the raiseGuardrailErrors flag.

  • Removed instanceof type checking for the context client, relying on try-catch for validation
  • Changed all error paths to return executionFailed: true with originalException instead of throwing
  • Updated error handling to preserve the actual error message rather than using generic fallback messages

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/checks/moderation.ts Refactored error handling to use executionFailed flag and originalException instead of throwing errors, removed instanceof check for client validation
src/tests/unit/checks/moderation-secret-keys.test.ts Updated tests to verify executionFailed flag and originalException are set correctly, added test for API key error handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@steven10a steven10a requested a review from Copilot November 3, 2025 20:11
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@steven10a steven10a requested a review from Copilot November 4, 2025 15:39
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +99 to +101
function ensureError(error: unknown): Error {
return error instanceof Error ? error : new Error(String(error));
}
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ensureError helper function is duplicating error normalization logic that exists in user-defined-llm.ts (line 139). Consider extracting this to a shared utility module to maintain consistency and reduce code duplication across guardrail implementations.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] I don't think we need to address this

Copy link
Collaborator

@gabor-openai gabor-openai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TY

@gabor-openai gabor-openai merged commit 6888a6b into main Nov 4, 2025
7 checks passed
@steven10a steven10a deleted the dev/steven/bug_21 branch November 10, 2025 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants