TestAsyncParse Class — anthropic-sdk-python Architecture
Architecture documentation for the TestAsyncParse class in test_messages.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD a421bd84_5b85_3e91_75b1_f60a7e36a8cd["TestAsyncParse"] 44ed7a88_b418_bef1_3a1d_fa5b630164d6["OrderItem"] a421bd84_5b85_3e91_75b1_f60a7e36a8cd -->|extends| 44ed7a88_b418_bef1_3a1d_fa5b630164d6 246dabb4_ab88_fde1_8813_0f3b472ae31c["OrderDetails"] a421bd84_5b85_3e91_75b1_f60a7e36a8cd -->|extends| 246dabb4_ab88_fde1_8813_0f3b472ae31c 2e600497_5282_f76f_a53c_ea19bd3e90f3["test_messages.py"] a421bd84_5b85_3e91_75b1_f60a7e36a8cd -->|defined in| 2e600497_5282_f76f_a53c_ea19bd3e90f3 adeff540_554f_9add_19d6_b593e312879a["test_parse_with_pydantic_model()"] a421bd84_5b85_3e91_75b1_f60a7e36a8cd -->|method| adeff540_554f_9add_19d6_b593e312879a 687440ff_6cea_5957_7b98_dbac4f003b74["test_parse_with_nested_pydantic_model()"] a421bd84_5b85_3e91_75b1_f60a7e36a8cd -->|method| 687440ff_6cea_5957_7b98_dbac4f003b74
Relationship Graph
Source Code
tests/lib/_parse/test_messages.py lines 96–159
class TestAsyncParse:
async def test_parse_with_pydantic_model(self, async_client: AsyncAnthropic, respx_mock: MockRouter) -> None:
"""Test async messages.parse() with a Pydantic model output_format."""
async def parse_message(c: AsyncAnthropic) -> ParsedMessage[OrderItem]:
return await c.messages.parse(
model="claude-sonnet-4-5",
messages=[
{
"role": "user",
"content": "Extract: I want to order 2 Green Tea at $5.50 each",
}
],
output_format=OrderItem,
max_tokens=1024,
)
response = await make_async_snapshot_request(
parse_message,
content_snapshot=snapshot(
'{"model":"claude-sonnet-4-5","id":"msg_01AsyncParseTest001","type":"message","role":"assistant","content":[{"type":"text","text":"{\\"product_name\\":\\"Green Tea\\",\\"price\\":5.5,\\"quantity\\":2}"}],"stop_reason":"end_turn","stop_sequence":null,"usage":{"input_tokens":50,"output_tokens":20}}'
),
respx_mock=respx_mock,
mock_client=async_client,
path="/v1/messages",
)
assert response.parsed_output is not None
assert isinstance(response.parsed_output, OrderItem)
assert response.parsed_output.product_name == "Green Tea"
assert response.parsed_output.price == 5.5
assert response.parsed_output.quantity == 2
async def test_parse_with_nested_pydantic_model(self, async_client: AsyncAnthropic, respx_mock: MockRouter) -> None:
"""Test async messages.parse() with nested Pydantic models."""
async def parse_message(c: AsyncAnthropic) -> ParsedMessage[OrderDetails]:
return await c.messages.parse(
model="claude-sonnet-4-5",
messages=[
{
"role": "user",
"content": "Extract order: 2 Green Tea at $5.50 and 1 Coffee at $3.00. Total $14.",
}
],
output_format=OrderDetails,
max_tokens=1024,
)
response = await make_async_snapshot_request(
parse_message,
content_snapshot=snapshot(
'{"model":"claude-sonnet-4-5","id":"msg_01AsyncParseTest002","type":"message","role":"assistant","content":[{"type":"text","text":"{\\"items\\":[{\\"product_name\\":\\"Green Tea\\",\\"price\\":5.5,\\"quantity\\":2},{\\"product_name\\":\\"Coffee\\",\\"price\\":3.0,\\"quantity\\":1}],\\"total\\":14.0}"}],"stop_reason":"end_turn","stop_sequence":null,"usage":{"input_tokens":60,"output_tokens":40}}'
),
respx_mock=respx_mock,
mock_client=async_client,
path="/v1/messages",
)
assert response.parsed_output is not None
assert isinstance(response.parsed_output, OrderDetails)
assert len(response.parsed_output.items) == 2
assert response.parsed_output.items[0].product_name == "Green Tea"
assert response.parsed_output.total == 14.0
Domain
Defined In
Extends
Source
Frequently Asked Questions
What is the TestAsyncParse class?
TestAsyncParse is a class in the anthropic-sdk-python codebase, defined in tests/lib/_parse/test_messages.py.
Where is TestAsyncParse defined?
TestAsyncParse is defined in tests/lib/_parse/test_messages.py at line 96.
What does TestAsyncParse extend?
TestAsyncParse extends OrderItem, OrderDetails.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free