From 3e74832ec9b55b3f78e802eb5c883a66e0255fe0 Mon Sep 17 00:00:00 2001 From: Vinicius Brasil Date: Thu, 18 Jun 2026 22:14:52 -0700 Subject: [PATCH] Avoid leaking output validation errors --- lib/crewai/src/crewai/tools/structured_tool.py | 3 ++- lib/crewai/tests/tools/test_structured_tool.py | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/crewai/src/crewai/tools/structured_tool.py b/lib/crewai/src/crewai/tools/structured_tool.py index 33b1c5f69..415722d14 100644 --- a/lib/crewai/src/crewai/tools/structured_tool.py +++ b/lib/crewai/src/crewai/tools/structured_tool.py @@ -74,7 +74,8 @@ def _format_tool_output_for_agent(tool: Any, raw_result: Any) -> str: ( f"Failed to validate or serialize output from tool " f"'{getattr(tool, 'name', '')}' using output_schema " - f"'{output_schema.__name__}': {exc}. Falling back to str(raw_result)." + f"'{output_schema.__name__}': {exc.__class__.__name__}. " + "Falling back to str(raw_result)." ), RuntimeWarning, stacklevel=2, diff --git a/lib/crewai/tests/tools/test_structured_tool.py b/lib/crewai/tests/tools/test_structured_tool.py index 4b29d8c8e..ed4b66d08 100644 --- a/lib/crewai/tests/tools/test_structured_tool.py +++ b/lib/crewai/tests/tools/test_structured_tool.py @@ -188,11 +188,16 @@ def test_invalid_typed_output_warns_and_uses_string_agent_text(): ) raw_result = tool.invoke({"value": "crew"}) - with pytest.warns(RuntimeWarning, match="Failed to validate or serialize"): + with pytest.warns( + RuntimeWarning, match="Failed to validate or serialize" + ) as warnings: agent_text = tool.format_output_for_agent(raw_result) assert raw_result == {"value": "crew", "count": "wrong"} assert agent_text == str(raw_result) + warning_message = str(warnings[0].message) + assert "ValidationError" in warning_message + assert "wrong" not in warning_message def test_validate_function_signature(basic_function, schema_class):