Skip to content

Commit 329a1bf

Browse files
update-input-guardrail-name (#1053)
# Ensure Fallback Name Handling in input_guardrail ## Problem The input_guardrail logic previously allowed the name attribute to be None if not explicitly provided. This caused issues in downstream systems such as logging, tracing, or serialization that expect a valid string name. ## Changes Introduced fallback logic to assign a default name if name is None. Guarantees that all function metadata includes a valid string name. Prevents unpredictable behavior or runtime errors in downstream processes. ## Impact Improves system robustness and fault tolerance. Ensures consistent behavior in tools relying on function names. No breaking changes introduced.
1 parent 72d0d75 commit 329a1bf

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/agents/guardrail.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,11 @@ async def my_async_guardrail(...): ...
241241
def decorator(
242242
f: _InputGuardrailFuncSync[TContext_co] | _InputGuardrailFuncAsync[TContext_co],
243243
) -> InputGuardrail[TContext_co]:
244-
return InputGuardrail(guardrail_function=f, name=name)
244+
return InputGuardrail(
245+
guardrail_function=f,
246+
# If not set, guardrail name uses the function’s name by default.
247+
name=name if name else f.__name__
248+
)
245249

246250
if func is not None:
247251
# Decorator was used without parentheses

0 commit comments

Comments
 (0)