Skip to content

Commit cdd9308

Browse files
committed
make check formatting
1 parent 198c8bd commit cdd9308

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

examples/basic/tool_guardrails.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def reject_phone_numbers(data: ToolOutputGuardrailData) -> ToolGuardrailFunction
9797
message="User data not retrieved as it contains a phone number which is restricted.",
9898
output_info={"redacted": "phone_number"},
9999
)
100-
return ToolGuardrailFunctionOutput()
100+
return ToolGuardrailFunctionOutput(output_info="Phone number check passed")
101101

102102

103103
# Apply guardrails to tools

src/agents/tool_guardrails.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import inspect
44
from collections.abc import Awaitable
5-
from dataclasses import dataclass
5+
from dataclasses import dataclass, field
66
from typing import TYPE_CHECKING, Any, Callable, Generic, Literal, overload
77

88
from typing_extensions import TypedDict, TypeVar
@@ -66,19 +66,16 @@ class ToolGuardrailFunctionOutput:
6666
information about the checks it performed and granular results.
6767
"""
6868

69-
behavior: RejectContentBehavior | RaiseExceptionBehavior | AllowBehavior | None = None
69+
behavior: RejectContentBehavior | RaiseExceptionBehavior | AllowBehavior = field(
70+
default_factory=lambda: AllowBehavior(type="allow")
71+
)
7072
"""
7173
Defines how the system should respond when this guardrail result is processed.
72-
- None/allow: Allow normal tool execution to continue without interference (default)
74+
- allow: Allow normal tool execution to continue without interference (default)
7375
- reject_content: Reject the tool call/output but continue execution with a message to the model
7476
- raise_exception: Halt execution by raising a ToolGuardrailTripwireTriggered exception
7577
"""
7678

77-
def __post_init__(self) -> None:
78-
"""Set default behavior if none specified."""
79-
if self.behavior is None:
80-
self.behavior = AllowBehavior(type="allow")
81-
8279
@classmethod
8380
def allow(cls, output_info: Any = None) -> ToolGuardrailFunctionOutput:
8481
"""Create a guardrail output that allows the tool execution to continue normally.

tests/extensions/memory/test_advanced_sqlite_session.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ def create_mock_run_result(
7070
final_output="test output",
7171
input_guardrail_results=[],
7272
output_guardrail_results=[],
73+
tool_input_guardrail_results=[],
74+
tool_output_guardrail_results=[],
7375
context_wrapper=context_wrapper,
7476
_last_agent=agent,
7577
)

tests/test_result_cast.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ def create_run_result(final_output: Any) -> RunResult:
1414
final_output=final_output,
1515
input_guardrail_results=[],
1616
output_guardrail_results=[],
17+
tool_input_guardrail_results=[],
18+
tool_output_guardrail_results=[],
1719
_last_agent=Agent(name="test"),
1820
context_wrapper=RunContextWrapper(context=None),
1921
)

0 commit comments

Comments
 (0)