def test_partial_json_with_invalid_json(self) -> None:
        """Test that invalid JSON raises an error."""
        message = BetaMessage(
            id="msg_123",
            type="message",
            role="assistant",
            content=[BetaToolUseBlock(type="tool_use", input={}, id="tool_123", name="test_tool")],
            model="claude-3-7-sonnet-20250219",
            stop_reason=None,
            stop_sequence=None,
            usage=BetaUsage(input_tokens=10, output_tokens=10),
        )

        # Invalid JSON input
        invalid_json = '{"key": "value", "incomplete_field": bad_value'
        event_invalid = BetaRawContentBlockDeltaEvent(
            type="content_block_delta",
            index=0,
            delta=BetaInputJSONDelta(type="input_json_delta", partial_json=invalid_json),
        )
        # Expect an error when trying to accumulate the invalid JSON
        try:
            accumulate_event(
                event=event_invalid,
                current_snapshot=copy.deepcopy(message),
                request_headers=httpx.Headers({"anthropic-beta": "fine-grained-tool-streaming-2025-05-14"}),
            )
            raise AssertionError("Expected ValueError for invalid JSON, but no error was raised.")
        except ValueError as e:
            assert str(e).startswith("Unable to parse tool parameter JSON from model. Please retry your request or adjust your prompt.")
        except Exception as e:
            raise AssertionError(f"Unexpected error type: {type(e).__name__} with message: {str(e)}") from e
Test that invalid JSON raises an error.
tests/lib/streaming/test_partial_json.py