An appeals court ruled Tuesday that the Trump administration cannot force LinkedIn to hand over 18 months of communications from journalists without narrowing its scope significantly.

The Department of Justice had requested data on multiple journalists who collectively published more than 1,000 articles across many topics. The request was not limited to journalists involved in reporting on classified military information but instead swept in journalists with any possible link to those involved in the story.

Judge J. Harvie Wilkinson III, writing for a unanimous three-judge panel, rejected the broad request. He found that it would capture "a vast number of confidential sources" of journalists "who have no conceivable relationship" to the leak investigation.

Wilkinson wrote that allowing such a request would silence dissidents raising alarms about "governmental behavior of dubious legality and integrity" and would "tip the balance against informed discourse in a manner inimical to democratic health."

The court also faulted the government's year-long secrecy order that prevented LinkedIn from disclosing the request to anyone. That left journalists unaware their First Amendment rights had been compromised, judges ruled.

Wilkinson rejected the government's argument that the order imposed no burden on LinkedIn simply because the company could feasibly compile the data. "It is not appropriate for district courts to approve requests purely because the records requested are logistically feasible to compile," he wrote.

The appeals court ordered the district court to narrow the order substantially. It specifically told the lower court to consider LinkedIn's alternative proposal: notifying a single attorney from the news outlet under investigation about the request. Wilkinson noted the government should explain why that narrow disclosure would compromise the investigation.

Microsoft, which owns LinkedIn, called the ruling "an important ruling for the right to privacy and press freedom." Civil rights groups including the Reporters Committee for Freedom of the Press, which backed LinkedIn, celebrated the decision as protecting confidential sources.