Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Set safety_identifier to openai-guardrails-python#37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
gabor-openai merged 3 commits intomainfromdev/steven/safety_identifiers
Oct 30, 2025

Conversation

@steven10a
Copy link
Collaborator

@steven10asteven10a commentedOct 30, 2025
edited
Loading

Fixingsafety_identifier implementation

  • Previously we were incorrectly adding safety_identifier as a HTTP header
  • Changed to use the supportedsafety_identifier parameter

Notesafety_identifier is only supported by the normal OpenAIresponses andchat.completions endpoint. Not implemented for Azure or third parties.

CopilotAI review requested due to automatic review settingsOctober 30, 2025 20:26
Copy link

CopilotAI 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 replaces the header-based safety identifier approach with a parameter-based approach for tracking guardrails library usage with the OpenAI API. The change removes the_openai_utils module that injected headers and instead conditionally adds asafety_identifier parameter to API calls when using the official OpenAI API (excluding Azure and alternative providers).

Key changes:

  • Removed_openai_utils.py module containing header-based safety identifier logic
  • Added_supports_safety_identifier() helper function in three locations to detect compatible clients
  • Updated all OpenAI client instantiations to removeprepare_openai_kwargs() wrapper calls
  • Added conditionalsafety_identifier parameter to LLM API calls based on client compatibility

Reviewed Changes

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

Show a summary per file
FileDescription
src/guardrails/_openai_utils.pyDeleted header-based safety identifier utilities module
src/guardrails/checks/text/llm_base.pyAdded safety identifier support detection and parameter injection for LLM checks
src/guardrails/resources/chat/chat.pyAdded safety identifier support detection and parameter injection for chat completions
src/guardrails/resources/responses/responses.pyAdded safety identifier support detection and parameter injection for responses API
src/guardrails/client.pyRemovedprepare_openai_kwargs() calls from client initialization
src/guardrails/agents.pyRemovedprepare_openai_kwargs() calls from default context creation
src/guardrails/runtime.pyRemovedprepare_openai_kwargs() calls from runtime default context
src/guardrails/evals/guardrail_evals.pyRemovedprepare_openai_kwargs() calls from eval client creation
src/guardrails/checks/text/moderation.pyRemovedprepare_openai_kwargs() calls from moderation client
src/guardrails/utils/create_vector_store.pyRemovedprepare_openai_kwargs() calls from vector store client
tests/unit/test_safety_identifier.pyAdded comprehensive tests for safety identifier support detection
tests/unit/test_openai_utils.pyDeleted tests for removed header-based utilities
tests/unit/test_agents.pyRemoved assertions checking for safety identifier headers

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

mock_client.base_url="https://example.openai.azure.com/v1"
mock_client.__class__.__name__="AsyncAzureOpenAI"

# Azure detection happens via isinstance check, but we can test with class name

Choose a reason for hiding this comment

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

This comment is misleading. The test creates a real Azure client and tests it with isinstance(), which is correct for llm_base.py. However, the chat.py and responses.py implementations use class name string matching instead, not isinstance checks.

Suggested change
# Azure detection happens via isinstance check, but we cantestwith class name
#In llm_base.py,Azure detection happens via isinstance check (thistestis correct).
# Note: chat.py and responses.py use class name string matching instead.

Copilot uses AI. Check for mistakes.
Copy link

CopilotAI 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 14 out of 14 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 65 to 71
__all__= [
"LLMConfig",
"LLMOutput",
"LLMErrorOutput",
"create_llm_check_fn",
"LLMOutput",
"create_error_result",
"create_llm_check_fn",
]

Choose a reason for hiding this comment

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

[nitpick] The__all__ list was reordered alphabetically, but this appears to be an incidental change unrelated to the PR's main purpose of refactoring the safety identifier. The previous ordering grouped related items together ('LLMConfig', 'LLMOutput', 'LLMErrorOutput', then functions). Consider reverting this change to keep the PR focused on its core objective.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@gabor-openaigabor-openai left a comment

Choose a reason for hiding this comment

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

LGTM ty!

Copy link
Collaborator

@gabor-openaigabor-openai left a comment

Choose a reason for hiding this comment

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

LGTM TY!

@gabor-openaigabor-openai changed the titlefixing safety identifierSet safety_identifier to openai-guardrails-pythonOct 30, 2025
@gabor-openaigabor-openai merged commit06fa983 intomainOct 30, 2025
3 checks passed
@gabor-openaigabor-openai deleted the dev/steven/safety_identifiers branchOctober 30, 2025 20:46
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

Copilot code reviewCopilotCopilot left review comments

@gabor-openaigabor-openaigabor-openai approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@steven10a@gabor-openai

[8]ページ先頭

©2009-2025 Movatter.jp