test_output_format_conversion.py — anthropic-sdk-python Source File
Architecture documentation for test_output_format_conversion.py, a python file in the anthropic-sdk-python codebase. 7 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 95c8f4d2_e4af_bb89_0668_a558e9dbecb5["test_output_format_conversion.py"] 28b0c811_20f6_fc4a_4b48_7fb9e87bf7e5["json"] 95c8f4d2_e4af_bb89_0668_a558e9dbecb5 --> 28b0c811_20f6_fc4a_4b48_7fb9e87bf7e5 dee4291e_ab30_b635_c404_0df76c542e94["warnings"] 95c8f4d2_e4af_bb89_0668_a558e9dbecb5 --> dee4291e_ab30_b635_c404_0df76c542e94 9c26e8a9_1ad2_1174_876a_1fc500ce0eaf["httpx"] 95c8f4d2_e4af_bb89_0668_a558e9dbecb5 --> 9c26e8a9_1ad2_1174_876a_1fc500ce0eaf cde8421b_93c7_41e4_d69d_2a3f1bade2f2["pytest"] 95c8f4d2_e4af_bb89_0668_a558e9dbecb5 --> cde8421b_93c7_41e4_d69d_2a3f1bade2f2 f6010db4_1656_22a8_b4ae_e0060d80d8c6["respx"] 95c8f4d2_e4af_bb89_0668_a558e9dbecb5 --> f6010db4_1656_22a8_b4ae_e0060d80d8c6 21de8837_7dae_989e_fdbb_1415c0770d90["pydantic"] 95c8f4d2_e4af_bb89_0668_a558e9dbecb5 --> 21de8837_7dae_989e_fdbb_1415c0770d90 d10c5377_2939_0f0b_cc44_8759393f2853["anthropic"] 95c8f4d2_e4af_bb89_0668_a558e9dbecb5 --> d10c5377_2939_0f0b_cc44_8759393f2853 style 95c8f4d2_e4af_bb89_0668_a558e9dbecb5 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Tests for output_format to output_config.format conversion and deprecation."""
import json
import warnings
import httpx
import pytest
from respx import MockRouter
from pydantic import BaseModel
from anthropic import Anthropic, AnthropicError, AsyncAnthropic, _compat
class TestOutputFormatConversion:
"""Test that output_format is properly converted to output_config.format."""
def test_create_converts_output_format_to_output_config(self, client: Anthropic, respx_mock: MockRouter) -> None:
"""Verify .create() converts output_format to output_config.format in request body."""
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": '{"result": "test"}', "type": "text"}],
"stop_reason": "end_turn",
"usage": {"input_tokens": 10, "output_tokens": 20},
},
)
)
with warnings.catch_warnings(record=True):
warnings.simplefilter("always")
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)
# Should have output_config with format
assert "output_config" in body
assert "format" in body["output_config"]
assert body["output_config"]["format"]["type"] == "json_schema"
assert body["output_config"]["format"]["schema"]["type"] == "object"
# Should NOT have output_format in request
assert "output_format" not in body
@pytest.mark.skipif(_compat.PYDANTIC_V1, reason="parse with Pydantic models requires Pydantic v2")
def test_parse_converts_pydantic_to_output_config(self, client: Anthropic, respx_mock: MockRouter) -> None:
"""Verify .parse() converts Pydantic models to output_config.format."""
class User(BaseModel):
name: str
// ... (535 more lines)
Domain
Subdomains
Classes
Dependencies
- anthropic
- httpx
- json
- pydantic
- pytest
- respx
- warnings
Source
Frequently Asked Questions
What does test_output_format_conversion.py do?
test_output_format_conversion.py is a source file in the anthropic-sdk-python codebase, written in python. It belongs to the AnthropicClient domain, Authentication subdomain.
What does test_output_format_conversion.py depend on?
test_output_format_conversion.py imports 7 module(s): anthropic, httpx, json, pydantic, pytest, respx, warnings.
Where is test_output_format_conversion.py in the architecture?
test_output_format_conversion.py is located at tests/api_resources/beta/test_output_format_conversion.py (domain: AnthropicClient, subdomain: Authentication, directory: tests/api_resources/beta).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free