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

test_async_parse_converts_pydantic() — anthropic-sdk-python Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  3c18c9e3_ae2d_985a_3ef3_ab78331cdeaa["test_async_parse_converts_pydantic()"]
  f4e94c7e_0d29_a411_d608_f21a1ae40401["TestAsyncOutputFormatConversion"]
  3c18c9e3_ae2d_985a_3ef3_ab78331cdeaa -->|defined in| f4e94c7e_0d29_a411_d608_f21a1ae40401
  style 3c18c9e3_ae2d_985a_3ef3_ab78331cdeaa fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

tests/api_resources/beta/test_output_format_conversion.py lines 532–567

    async def test_async_parse_converts_pydantic(self, async_client: AsyncAnthropic, respx_mock: MockRouter) -> None:
        """Verify async .parse() converts Pydantic models to output_config.format."""

        class User(BaseModel):
            name: str

        respx_mock.post("/v1/messages?beta=true").mock(
            return_value=httpx.Response(
                200,
                json={
                    "id": "msg_123",
                    "type": "message",
                    "role": "assistant",
                    "model": "claude-sonnet-4-5",
                    "content": [{"text": '{"name": "John"}', "type": "text"}],
                    "stop_reason": "end_turn",
                    "usage": {"input_tokens": 10, "output_tokens": 20},
                },
            )
        )

        with warnings.catch_warnings(record=True):
            warnings.simplefilter("always")
            await async_client.beta.messages.parse(
                max_tokens=1024,
                messages=[{"role": "user", "content": "Test"}],
                model="claude-sonnet-4-5",
                output_format=User,
            )

        request = respx_mock.calls.last.request
        body = json.loads(request.content)

        assert "output_config" in body
        assert "format" in body["output_config"]
        assert "output_format" not in body

Subdomains

Frequently Asked Questions

What does test_async_parse_converts_pydantic() do?
test_async_parse_converts_pydantic() is a function in the anthropic-sdk-python codebase, defined in tests/api_resources/beta/test_output_format_conversion.py.
Where is test_async_parse_converts_pydantic() defined?
test_async_parse_converts_pydantic() is defined in tests/api_resources/beta/test_output_format_conversion.py at line 532.

Analyze Your Own Codebase

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

Try Supermodel Free