test_trailing_strings_mode_header() — anthropic-sdk-python Function Reference
Architecture documentation for the test_trailing_strings_mode_header() function in test_partial_json.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD 9bb433d5_32a1_98ef_213f_282d61ed1f22["test_trailing_strings_mode_header()"] c520095b_d21b_0a1f_51f9_db7cbf763449["TestPartialJson"] 9bb433d5_32a1_98ef_213f_282d61ed1f22 -->|defined in| c520095b_d21b_0a1f_51f9_db7cbf763449 style 9bb433d5_32a1_98ef_213f_282d61ed1f22 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
tests/lib/streaming/test_partial_json.py lines 14–105
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
incomplete_json = '{"items": ["item1", "item2"], "unfinished_field": "incomplete value'
event_incomplete = BetaRawContentBlockDeltaEvent(
type="content_block_delta",
index=0,
delta=BetaInputJSONDelta(type="input_json_delta", partial_json=incomplete_json),
)
# Without beta header (standard mode)
message_standard = accumulate_event(
event=event_incomplete,
current_snapshot=copy.deepcopy(message),
request_headers=httpx.Headers({"some-header": "value"}),
)
# With beta header (trailing strings mode)
message_trailing = accumulate_event(
event=event_incomplete,
current_snapshot=copy.deepcopy(message),
request_headers=httpx.Headers({"anthropic-beta": "fine-grained-tool-streaming-2025-05-14"}),
)
# Get the tool use blocks
standard_tool = cast(ToolUseBlock, message_standard.content[0])
trailing_tool = cast(ToolUseBlock, message_trailing.content[0])
# Both should have the valid complete part of the JSON
assert isinstance(standard_tool.input, dict)
assert isinstance(trailing_tool.input, dict)
standard_input = standard_tool.input # type: ignore
trailing_input = trailing_tool.input # type: ignore
# The input should have the items array in both cases
items_standard = cast(List[str], standard_input["items"])
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does test_trailing_strings_mode_header() do?
test_trailing_strings_mode_header() is a function in the anthropic-sdk-python codebase, defined in tests/lib/streaming/test_partial_json.py.
Where is test_trailing_strings_mode_header() defined?
test_trailing_strings_mode_header() is defined in tests/lib/streaming/test_partial_json.py at line 14.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free