Skip to content

Commit 3e74832

Browse files
committed
Avoid leaking output validation errors
1 parent 7d83342 commit 3e74832

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

lib/crewai/src/crewai/tools/structured_tool.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ def _format_tool_output_for_agent(tool: Any, raw_result: Any) -> str:
7474
(
7575
f"Failed to validate or serialize output from tool "
7676
f"'{getattr(tool, 'name', '<unknown>')}' using output_schema "
77-
f"'{output_schema.__name__}': {exc}. Falling back to str(raw_result)."
77+
f"'{output_schema.__name__}': {exc.__class__.__name__}. "
78+
"Falling back to str(raw_result)."
7879
),
7980
RuntimeWarning,
8081
stacklevel=2,

lib/crewai/tests/tools/test_structured_tool.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,16 @@ def build_value(value: str) -> dict[str, object]:
188188
)
189189
raw_result = tool.invoke({"value": "crew"})
190190

191-
with pytest.warns(RuntimeWarning, match="Failed to validate or serialize"):
191+
with pytest.warns(
192+
RuntimeWarning, match="Failed to validate or serialize"
193+
) as warnings:
192194
agent_text = tool.format_output_for_agent(raw_result)
193195

194196
assert raw_result == {"value": "crew", "count": "wrong"}
195197
assert agent_text == str(raw_result)
198+
warning_message = str(warnings[0].message)
199+
assert "ValidationError" in warning_message
200+
assert "wrong" not in warning_message
196201

197202

198203
def test_validate_function_signature(basic_function, schema_class):

0 commit comments

Comments
 (0)