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

TestAsyncOutputFormatConversion Class — anthropic-sdk-python Architecture

Architecture documentation for the TestAsyncOutputFormatConversion class in test_output_format_conversion.py from the anthropic-sdk-python codebase.

Entity Profile

Dependency Diagram

graph TD
  f4e94c7e_0d29_a411_d608_f21a1ae40401["TestAsyncOutputFormatConversion"]
  17ce5647_6f06_0676_a4a5_e378a3f57cb1["BaseModel"]
  f4e94c7e_0d29_a411_d608_f21a1ae40401 -->|extends| 17ce5647_6f06_0676_a4a5_e378a3f57cb1
  95c8f4d2_e4af_bb89_0668_a558e9dbecb5["test_output_format_conversion.py"]
  f4e94c7e_0d29_a411_d608_f21a1ae40401 -->|defined in| 95c8f4d2_e4af_bb89_0668_a558e9dbecb5
  cc2da03b_be06_ba19_ba25_1a99f7854b33["test_async_create_converts_output_format()"]
  f4e94c7e_0d29_a411_d608_f21a1ae40401 -->|method| cc2da03b_be06_ba19_ba25_1a99f7854b33
  3c18c9e3_ae2d_985a_3ef3_ab78331cdeaa["test_async_parse_converts_pydantic()"]
  f4e94c7e_0d29_a411_d608_f21a1ae40401 -->|method| 3c18c9e3_ae2d_985a_3ef3_ab78331cdeaa
  d6b3d2e8_b964_d94d_b290_489fb9d5b9b5["test_async_methods_emit_deprecation_warnings()"]
  f4e94c7e_0d29_a411_d608_f21a1ae40401 -->|method| d6b3d2e8_b964_d94d_b290_489fb9d5b9b5

Relationship Graph

Source Code

tests/api_resources/beta/test_output_format_conversion.py lines 493–594

class TestAsyncOutputFormatConversion:
    """Test async variants of output_format conversion."""

    async def test_async_create_converts_output_format(
        self, async_client: AsyncAnthropic, respx_mock: MockRouter
    ) -> None:
        """Verify async .create() converts output_format to output_config.format."""
        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": "test", "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.create(
                max_tokens=1024,
                messages=[{"role": "user", "content": "Test"}],
                model="claude-sonnet-4-5",
                output_format={"type": "json_schema", "schema": {"type": "object"}},
            )

        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

    @pytest.mark.skipif(_compat.PYDANTIC_V1, reason="parse with Pydantic models requires Pydantic v2")
    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

    async def test_async_methods_emit_deprecation_warnings(
        self, async_client: AsyncAnthropic, respx_mock: MockRouter
    ) -> None:
        """Verify async methods emit DeprecationWarning."""
        respx_mock.post("/v1/messages?beta=true").mock(

Extends

Frequently Asked Questions

What is the TestAsyncOutputFormatConversion class?
TestAsyncOutputFormatConversion is a class in the anthropic-sdk-python codebase, defined in tests/api_resources/beta/test_output_format_conversion.py.
Where is TestAsyncOutputFormatConversion defined?
TestAsyncOutputFormatConversion is defined in tests/api_resources/beta/test_output_format_conversion.py at line 493.
What does TestAsyncOutputFormatConversion extend?
TestAsyncOutputFormatConversion extends BaseModel.

Analyze Your Own Codebase

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

Try Supermodel Free