Skip to content

test: cover guardrail name fallback to function __name__#3073

Merged
seratch merged 1 commit intoopenai:mainfrom
Quratulain-bilal:test/guardrail-name-fallback-coverage
May 1, 2026
Merged

test: cover guardrail name fallback to function __name__#3073
seratch merged 1 commit intoopenai:mainfrom
Quratulain-bilal:test/guardrail-name-fallback-coverage

Conversation

@Quratulain-bilal
Copy link
Copy Markdown
Contributor

Summary

Adds regression coverage for the guardrail name fallback behavior introduced in #1053.

When @input_guardrail, @output_guardrail, @tool_input_guardrail, or @tool_output_guardrail are used without an
explicit name=, get_name() should return the decorated function's __name__. The existing tests only verified the
explicit-name path, leaving the fallback uncovered.

Changes

  • tests/test_guardrails.py: assert get_name() == "decorated_input_guardrail" / "decorated_output_guardrail" for
    the unnamed decorators.
  • tests/test_tool_guardrails.py: same assertion for tool_input_guardrail / tool_output_guardrail.

No runtime code changes.

Test plan

  • uv run pytest tests/test_guardrails.py tests/test_tool_guardrails.py — 53 passed
  • uv run ruff format --check clean
  • uv run ruff check clean

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.
@Quratulain-bilal Quratulain-bilal force-pushed the test/guardrail-name-fallback-coverage branch from 71c878f to d927822 Compare May 1, 2026 12:04
Copy link
Copy Markdown
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

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

Thanks. Indeed, these should have been added back then!

@seratch seratch merged commit ae224b4 into openai:main May 1, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants