Avoid leaking output validation errors

This commit is contained in:
Vinicius Brasil
2026-06-18 22:14:52 -07:00
parent 7d8334268e
commit 3e74832ec9
2 changed files with 8 additions and 2 deletions

View File

@@ -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', '<unknown>')}' 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,

View File

@@ -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):