test_parse_with_pydantic_model() — anthropic-sdk-python Function Reference
Architecture documentation for the test_parse_with_pydantic_model() function in test_messages.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD adeff540_554f_9add_19d6_b593e312879a["test_parse_with_pydantic_model()"] a421bd84_5b85_3e91_75b1_f60a7e36a8cd["TestAsyncParse"] adeff540_554f_9add_19d6_b593e312879a -->|defined in| a421bd84_5b85_3e91_75b1_f60a7e36a8cd bede6c65_274f_7b15_9da7_05caaf37de2d["test_parse_with_pydantic_model()"] bede6c65_274f_7b15_9da7_05caaf37de2d -->|calls| adeff540_554f_9add_19d6_b593e312879a bede6c65_274f_7b15_9da7_05caaf37de2d["test_parse_with_pydantic_model()"] adeff540_554f_9add_19d6_b593e312879a -->|calls| bede6c65_274f_7b15_9da7_05caaf37de2d style adeff540_554f_9add_19d6_b593e312879a fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
tests/lib/_parse/test_messages.py lines 97–127
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
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does test_parse_with_pydantic_model() do?
test_parse_with_pydantic_model() is a function in the anthropic-sdk-python codebase, defined in tests/lib/_parse/test_messages.py.
Where is test_parse_with_pydantic_model() defined?
test_parse_with_pydantic_model() is defined in tests/lib/_parse/test_messages.py at line 97.
What does test_parse_with_pydantic_model() call?
test_parse_with_pydantic_model() calls 1 function(s): test_parse_with_pydantic_model.
What calls test_parse_with_pydantic_model()?
test_parse_with_pydantic_model() is called by 1 function(s): test_parse_with_pydantic_model.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free