Skip to content

Commit b41f23b

Browse files
WorkWork
authored andcommitted
fix: pass message to ToolRetryError parent class
ToolRetryError was not passing a message to Exception.__init__(), causing str(error) to return an empty string. This breaks error monitoring tools like Sentry that rely on str(exception) to display error messages. The fix passes tool_retry.model_response() to the parent class, ensuring the error message is properly accessible via str(error) and error.args.
1 parent 87ad3d5 commit b41f23b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

pydantic_ai_slim/pydantic_ai/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class ToolRetryError(Exception):
188188

189189
def __init__(self, tool_retry: RetryPromptPart):
190190
self.tool_retry = tool_retry
191-
super().__init__()
191+
super().__init__(tool_retry.model_response())
192192

193193

194194
class IncompleteToolCall(UnexpectedModelBehavior):

tests/test_exceptions.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
IncompleteToolCall,
1414
ModelAPIError,
1515
ModelHTTPError,
16+
ToolRetryError,
1617
UnexpectedModelBehavior,
1718
UsageLimitExceeded,
1819
UserError,
1920
)
21+
from pydantic_ai.messages import RetryPromptPart
2022

2123

2224
@pytest.mark.parametrize(
@@ -32,6 +34,7 @@
3234
lambda: ModelAPIError('model', 'test message'),
3335
lambda: ModelHTTPError(500, 'model'),
3436
lambda: IncompleteToolCall('test'),
37+
lambda: ToolRetryError(RetryPromptPart(content='test', tool_name='test')),
3538
],
3639
ids=[
3740
'ModelRetry',
@@ -44,6 +47,7 @@
4447
'ModelAPIError',
4548
'ModelHTTPError',
4649
'IncompleteToolCall',
50+
'ToolRetryError',
4751
],
4852
)
4953
def test_exceptions_hashable(exc_factory: Callable[[], Any]):
@@ -59,3 +63,11 @@ def test_exceptions_hashable(exc_factory: Callable[[], Any]):
5963

6064
assert exc in s
6165
assert d[exc] == 'value'
66+
67+
68+
def test_tool_retry_error_str():
69+
"""Test that ToolRetryError has a meaningful string representation."""
70+
71+
part = RetryPromptPart(content='Invalid query syntax', tool_name='sql_query')
72+
error = ToolRetryError(part)
73+
assert 'Invalid query syntax' in str(error)

0 commit comments

Comments
 (0)