Home / Class/ TestSyncParse Class — anthropic-sdk-python Architecture

TestSyncParse Class — anthropic-sdk-python Architecture

Architecture documentation for the TestSyncParse class in test_messages.py from the anthropic-sdk-python codebase.

Entity Profile

Dependency Diagram

graph TD
  73716534_3a5c_3a9d_37ab_a7a48c3de637["TestSyncParse"]
  44ed7a88_b418_bef1_3a1d_fa5b630164d6["OrderItem"]
  73716534_3a5c_3a9d_37ab_a7a48c3de637 -->|extends| 44ed7a88_b418_bef1_3a1d_fa5b630164d6
  246dabb4_ab88_fde1_8813_0f3b472ae31c["OrderDetails"]
  73716534_3a5c_3a9d_37ab_a7a48c3de637 -->|extends| 246dabb4_ab88_fde1_8813_0f3b472ae31c
  2e600497_5282_f76f_a53c_ea19bd3e90f3["test_messages.py"]
  73716534_3a5c_3a9d_37ab_a7a48c3de637 -->|defined in| 2e600497_5282_f76f_a53c_ea19bd3e90f3
  bede6c65_274f_7b15_9da7_05caaf37de2d["test_parse_with_pydantic_model()"]
  73716534_3a5c_3a9d_37ab_a7a48c3de637 -->|method| bede6c65_274f_7b15_9da7_05caaf37de2d
  02b471d4_f169_8537_0e85_f32b8b43cee4["test_parse_with_nested_pydantic_model()"]
  73716534_3a5c_3a9d_37ab_a7a48c3de637 -->|method| 02b471d4_f169_8537_0e85_f32b8b43cee4

Relationship Graph

Source Code

tests/lib/_parse/test_messages.py lines 27–92

class TestSyncParse:
    @pytest.mark.respx(base_url="http://127.0.0.1:4010")
    def test_parse_with_pydantic_model(self, client: Anthropic, respx_mock: MockRouter) -> None:
        """Test sync messages.parse() with a Pydantic model output_format."""

        def parse_message(c: Anthropic) -> ParsedMessage[OrderItem]:
            return 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 = make_snapshot_request(
            parse_message,
            content_snapshot=snapshot(
                '{"model":"claude-sonnet-4-5","id":"msg_01ParseTest001","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=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

    @pytest.mark.respx(base_url="http://127.0.0.1:4010")
    def test_parse_with_nested_pydantic_model(self, client: Anthropic, respx_mock: MockRouter) -> None:
        """Test sync messages.parse() with nested Pydantic models."""

        def parse_message(c: Anthropic) -> ParsedMessage[OrderDetails]:
            return 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 = make_snapshot_request(
            parse_message,
            content_snapshot=snapshot(
                '{"model":"claude-sonnet-4-5","id":"msg_01ParseTest002","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=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

Frequently Asked Questions

What is the TestSyncParse class?
TestSyncParse is a class in the anthropic-sdk-python codebase, defined in tests/lib/_parse/test_messages.py.
Where is TestSyncParse defined?
TestSyncParse is defined in tests/lib/_parse/test_messages.py at line 27.
What does TestSyncParse extend?
TestSyncParse extends OrderItem, OrderDetails.

Analyze Your Own Codebase

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

Try Supermodel Free