@@ -687,6 +687,8 @@ def function_tool(
687687 failure_error_function : ToolErrorFunction | None = None ,
688688 strict_mode : bool = True ,
689689 is_enabled : bool | Callable [[RunContextWrapper [Any ], AgentBase ], MaybeAwaitable [bool ]] = True ,
690+ tool_input_guardrails : list [ToolInputGuardrail [Any ]] | None = None ,
691+ tool_output_guardrails : list [ToolOutputGuardrail [Any ]] | None = None ,
690692) -> FunctionTool :
691693 """Overload for usage as @function_tool (no parentheses)."""
692694 ...
@@ -702,6 +704,8 @@ def function_tool(
702704 failure_error_function : ToolErrorFunction | None = None ,
703705 strict_mode : bool = True ,
704706 is_enabled : bool | Callable [[RunContextWrapper [Any ], AgentBase ], MaybeAwaitable [bool ]] = True ,
707+ tool_input_guardrails : list [ToolInputGuardrail [Any ]] | None = None ,
708+ tool_output_guardrails : list [ToolOutputGuardrail [Any ]] | None = None ,
705709) -> Callable [[ToolFunction [...]], FunctionTool ]:
706710 """Overload for usage as @function_tool(...)."""
707711 ...
@@ -717,6 +721,8 @@ def function_tool(
717721 failure_error_function : ToolErrorFunction | None = default_tool_error_function ,
718722 strict_mode : bool = True ,
719723 is_enabled : bool | Callable [[RunContextWrapper [Any ], AgentBase ], MaybeAwaitable [bool ]] = True ,
724+ tool_input_guardrails : list [ToolInputGuardrail [Any ]] | None = None ,
725+ tool_output_guardrails : list [ToolOutputGuardrail [Any ]] | None = None ,
720726) -> FunctionTool | Callable [[ToolFunction [...]], FunctionTool ]:
721727 """
722728 Decorator to create a FunctionTool from a function. By default, we will:
@@ -748,6 +754,8 @@ def function_tool(
748754 is_enabled: Whether the tool is enabled. Can be a bool or a callable that takes the run
749755 context and agent and returns whether the tool is enabled. Disabled tools are hidden
750756 from the LLM at runtime.
757+ tool_input_guardrails: Optional list of guardrails to run before invoking the tool.
758+ tool_output_guardrails: Optional list of guardrails to run after the tool returns.
751759 """
752760
753761 def _create_function_tool (the_func : ToolFunction [...]) -> FunctionTool :
@@ -845,6 +853,8 @@ async def _on_invoke_tool(ctx: ToolContext[Any], input: str) -> Any:
845853 on_invoke_tool = _on_invoke_tool ,
846854 strict_json_schema = strict_mode ,
847855 is_enabled = is_enabled ,
856+ tool_input_guardrails = tool_input_guardrails ,
857+ tool_output_guardrails = tool_output_guardrails ,
848858 )
849859
850860 # If func is actually a callable, we were used as @function_tool with no parentheses
0 commit comments