The US patent statute requires that an invention be "useful." 35 U.S.C. 101. Under the law, an inveention's utility must be "specific, substantial, and credible" and an invention lacking utility cannot be patented.
As a matter of practice, the utility doctrine is applied quite differently depending upon the context. For example, the US Patent Office requires evidence that a new pharmaceutical will work for its intended purpose rather than simply trusting the patent applicants claims that it works. On the other hand, the Patent Office's general practice has been to trust the applicant that the invention would actually work for its intended purpose.
The result then is that for software, the USPTO simply assumes utility in the vast majority of cases. I should say here that I expect that this will change over the next decade, but that is a long horizon.