test_partial_json.py — anthropic-sdk-python Source File
Architecture documentation for test_partial_json.py, a python file in the anthropic-sdk-python codebase. 8 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 06ef3a78_b4c0_f7a7_8dcb_f5667ebd7320["test_partial_json.py"] 30408ccb_01be_d829_7c8f_547c414bd1bb["copy"] 06ef3a78_b4c0_f7a7_8dcb_f5667ebd7320 --> 30408ccb_01be_d829_7c8f_547c414bd1bb 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875["typing"] 06ef3a78_b4c0_f7a7_8dcb_f5667ebd7320 --> 89ddcdd7_3ae1_4c7b_41bb_9f1e25f16875 9c26e8a9_1ad2_1174_876a_1fc500ce0eaf["httpx"] 06ef3a78_b4c0_f7a7_8dcb_f5667ebd7320 --> 9c26e8a9_1ad2_1174_876a_1fc500ce0eaf 02abf1f6_b512_32df_c4f5_940df96192d8["anthropic.types.beta"] 06ef3a78_b4c0_f7a7_8dcb_f5667ebd7320 --> 02abf1f6_b512_32df_c4f5_940df96192d8 4cc182a3_5e45_f306_2b15_341e75efe9b2["anthropic.types.tool_use_block"] 06ef3a78_b4c0_f7a7_8dcb_f5667ebd7320 --> 4cc182a3_5e45_f306_2b15_341e75efe9b2 a9d910e8_38d9_7870_baa9_7aa1d89958a4["anthropic.types.beta.beta_usage"] 06ef3a78_b4c0_f7a7_8dcb_f5667ebd7320 --> a9d910e8_38d9_7870_baa9_7aa1d89958a4 4844e113_0361_b762_1267_974223d4f676["anthropic.lib.streaming._beta_messages"] 06ef3a78_b4c0_f7a7_8dcb_f5667ebd7320 --> 4844e113_0361_b762_1267_974223d4f676 c6e963a0_47d8_f3d4_54b1_cd562f2c420d["anthropic.types.beta.parsed_beta_message"] 06ef3a78_b4c0_f7a7_8dcb_f5667ebd7320 --> c6e963a0_47d8_f3d4_54b1_cd562f2c420d style 06ef3a78_b4c0_f7a7_8dcb_f5667ebd7320 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import copy
from typing import List, cast
import httpx
from anthropic.types.beta import BetaDirectCaller, BetaToolUseBlock, BetaInputJSONDelta, BetaRawContentBlockDeltaEvent
from anthropic.types.tool_use_block import ToolUseBlock
from anthropic.types.beta.beta_usage import BetaUsage
from anthropic.lib.streaming._beta_messages import accumulate_event
from anthropic.types.beta.parsed_beta_message import ParsedBetaMessage
class TestPartialJson:
def test_trailing_strings_mode_header(self) -> None:
"""Test behavior differences with and without the beta header for JSON parsing."""
message = ParsedBetaMessage(
id="msg_123",
type="message",
role="assistant",
content=[
BetaToolUseBlock(
type="tool_use",
input={},
id="tool_123",
name="test_tool",
caller=BetaDirectCaller(type="direct"),
)
],
model="claude-sonnet-4-5",
stop_reason=None,
stop_sequence=None,
usage=BetaUsage(input_tokens=10, output_tokens=10),
)
# Test case 1: Complete JSON
complete_json = '{"key": "value"}'
event_complete = BetaRawContentBlockDeltaEvent(
type="content_block_delta",
index=0,
delta=BetaInputJSONDelta(type="input_json_delta", partial_json=complete_json),
)
# Both modes should handle complete JSON the same way
message1 = accumulate_event(
event=event_complete,
current_snapshot=copy.deepcopy(message),
request_headers=httpx.Headers({"some-header": "value"}),
)
message2 = accumulate_event(
event=event_complete,
current_snapshot=copy.deepcopy(message),
request_headers=httpx.Headers({"anthropic-beta": "fine-grained-tool-streaming-2025-05-14"}),
)
# Both should parse complete JSON correctly
assert cast(ToolUseBlock, message1.content[0]).input == {"key": "value"}
assert cast(ToolUseBlock, message2.content[0]).input == {"key": "value"}
# Test case 2: Incomplete JSON with trailing string that will be treated differently
# Here we want to create a situation where regular mode and trailing strings mode behave differently
// ... (90 more lines)
Domain
Subdomains
Classes
Dependencies
- anthropic.lib.streaming._beta_messages
- anthropic.types.beta
- anthropic.types.beta.beta_usage
- anthropic.types.beta.parsed_beta_message
- anthropic.types.tool_use_block
- copy
- httpx
- typing
Source
Frequently Asked Questions
What does test_partial_json.py do?
test_partial_json.py is a source file in the anthropic-sdk-python codebase, written in python. It belongs to the AnthropicClient domain, AsyncAPI subdomain.
What does test_partial_json.py depend on?
test_partial_json.py imports 8 module(s): anthropic.lib.streaming._beta_messages, anthropic.types.beta, anthropic.types.beta.beta_usage, anthropic.types.beta.parsed_beta_message, anthropic.types.tool_use_block, copy, httpx, typing.
Where is test_partial_json.py in the architecture?
test_partial_json.py is located at tests/lib/streaming/test_partial_json.py (domain: AnthropicClient, subdomain: AsyncAPI, directory: tests/lib/streaming).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free