test: cover guardrail name fallback to function __name__#3073
Merged
seratch merged 1 commit intoopenai:mainfrom May 1, 2026
Merged
Conversation
Adds assertions to verify get_name() returns the decorated function's __name__ when no explicit name is provided to @input_guardrail, @output_guardrail, @tool_input_guardrail, and @tool_output_guardrail. Locks in the fallback behavior introduced in openai#1053 and mirrors it for tool guardrails.
71c878f to
d927822
Compare
seratch
approved these changes
May 1, 2026
Member
seratch
left a comment
There was a problem hiding this comment.
Thanks. Indeed, these should have been added back then!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds regression coverage for the guardrail
namefallback behavior introduced in #1053.When
@input_guardrail,@output_guardrail,@tool_input_guardrail, or@tool_output_guardrailare used without anexplicit
name=,get_name()should return the decorated function's__name__. The existing tests only verified theexplicit-name path, leaving the fallback uncovered.
Changes
tests/test_guardrails.py: assertget_name() == "decorated_input_guardrail"/"decorated_output_guardrail"forthe unnamed decorators.
tests/test_tool_guardrails.py: same assertion fortool_input_guardrail/tool_output_guardrail.No runtime code changes.
Test plan
uv run pytest tests/test_guardrails.py tests/test_tool_guardrails.py— 53 passeduv run ruff format --checkcleanuv run ruff checkclean