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.

Function python AnthropicClient AsyncAPI calls 1 called by 1

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

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

    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

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 62.
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