test_tool_call_error() — anthropic-sdk-python Function Reference
Architecture documentation for the test_tool_call_error() function in test_runners.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD c6cb9700_00c6_527f_dcfd_c498f856fc40["test_tool_call_error()"] 6847e1ae_03a4_3e19_19ff_ea808e74d94c["TestSyncRunTools"] c6cb9700_00c6_527f_dcfd_c498f856fc40 -->|defined in| 6847e1ae_03a4_3e19_19ff_ea808e74d94c be8a7f3a_5951_1f73_7331_3ad05c999ecf["_get_weather()"] c6cb9700_00c6_527f_dcfd_c498f856fc40 -->|calls| be8a7f3a_5951_1f73_7331_3ad05c999ecf style c6cb9700_00c6_527f_dcfd_c498f856fc40 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
tests/lib/tools/test_runners.py lines 110–170
def test_tool_call_error(
self,
client: Anthropic,
respx_mock: MockRouter,
monkeypatch: pytest.MonkeyPatch,
caplog: pytest.LogCaptureFixture,
) -> None:
called = None
@beta_tool
def get_weather(location: str, units: Literal["c", "f"]) -> BetaFunctionToolResultType:
"""Lookup the weather for a given city in either celsius or fahrenheit
Args:
location: The city and state, e.g. San Francisco, CA
units: Unit for the output, either 'c' for celsius or 'f' for fahrenheit
Returns:
A dictionary containing the location, temperature, and weather condition.
"""
nonlocal called
if called is None:
called = True
raise RuntimeError("Unexpected error, try again")
return json.dumps(_get_weather(location, units))
def tool_runner(client: Anthropic) -> List[Union[BetaMessageParam, None]]:
runner = client.beta.messages.tool_runner(
max_tokens=1024,
model="claude-haiku-4-5",
tools=[get_weather],
messages=[{"role": "user", "content": "What is the weather in SF?"}],
)
actual_responses: List[Union[BetaMessageParam, None]] = []
for _ in runner:
tool_call_response = runner.generate_tool_call_response()
if tool_call_response is not None:
actual_responses.append(tool_call_response)
return actual_responses
with caplog.at_level(logging.ERROR):
message = make_snapshot_request(
tool_runner,
content_snapshot=snapshots["tool_call_error"]["responses"],
path="/v1/messages",
mock_client=client,
respx_mock=respx_mock,
)
assert caplog.record_tuples == [
(
"anthropic.lib.tools._beta_runner",
logging.ERROR,
"Error occurred while calling tool: get_weather",
),
]
assert print_obj(message, monkeypatch) == snapshot(
"[{'role': 'user', 'content': [{'type': 'tool_result', 'tool_use_id': 'toolu_01Do4cDVNxt51EuosKoxdmii', 'content': \"RuntimeError('Unexpected error, try again')\", 'is_error': True}]}]\n"
)
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does test_tool_call_error() do?
test_tool_call_error() is a function in the anthropic-sdk-python codebase, defined in tests/lib/tools/test_runners.py.
Where is test_tool_call_error() defined?
test_tool_call_error() is defined in tests/lib/tools/test_runners.py at line 110.
What does test_tool_call_error() call?
test_tool_call_error() calls 1 function(s): _get_weather.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free