Home / Function/ test_parse_with_nested_pydantic_model() — anthropic-sdk-python Function Reference

test_parse_with_nested_pydantic_model() — anthropic-sdk-python Function Reference

Architecture documentation for the test_parse_with_nested_pydantic_model() function in test_messages.py from the anthropic-sdk-python codebase.

Entity Profile

Dependency Diagram

graph TD
  687440ff_6cea_5957_7b98_dbac4f003b74["test_parse_with_nested_pydantic_model()"]
  a421bd84_5b85_3e91_75b1_f60a7e36a8cd["TestAsyncParse"]
  687440ff_6cea_5957_7b98_dbac4f003b74 -->|defined in| a421bd84_5b85_3e91_75b1_f60a7e36a8cd
  02b471d4_f169_8537_0e85_f32b8b43cee4["test_parse_with_nested_pydantic_model()"]
  02b471d4_f169_8537_0e85_f32b8b43cee4 -->|calls| 687440ff_6cea_5957_7b98_dbac4f003b74
  02b471d4_f169_8537_0e85_f32b8b43cee4["test_parse_with_nested_pydantic_model()"]
  687440ff_6cea_5957_7b98_dbac4f003b74 -->|calls| 02b471d4_f169_8537_0e85_f32b8b43cee4
  style 687440ff_6cea_5957_7b98_dbac4f003b74 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

tests/lib/_parse/test_messages.py lines 129–159

    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

Subdomains

Frequently Asked Questions

What does test_parse_with_nested_pydantic_model() do?
test_parse_with_nested_pydantic_model() is a function in the anthropic-sdk-python codebase, defined in tests/lib/_parse/test_messages.py.
Where is test_parse_with_nested_pydantic_model() defined?
test_parse_with_nested_pydantic_model() is defined in tests/lib/_parse/test_messages.py at line 129.
What does test_parse_with_nested_pydantic_model() call?
test_parse_with_nested_pydantic_model() calls 1 function(s): test_parse_with_nested_pydantic_model.
What calls test_parse_with_nested_pydantic_model()?
test_parse_with_nested_pydantic_model() is called by 1 function(s): test_parse_with_nested_pydantic_model.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free