Aug. 28 (UPI) -- A federal judge in northern California ruled that the U.S. Defense Department's sanctioning of AI firm Anthropic as a security risk was unlawful.

In her decision Thursday, U.S. District Judge Rita Lin agreed with Anthropic's case that Defense Secretary Pete Hegseth had exceeded his authority by ordering contractors supplying the U.S. military not to use, or do business with, Anthropic.

Lin said the Pentagon had acted out of retaliation and in violation of Anthropic's First Amendment free speech rights.

The ban in February came after Anthorpic said it would not permit the use of its AI models by the U.S. military for purposes such as domestic surveillance and autonomous weapons systems, saying surveillance of Americans violated their rights and that its technology was not safe to use in systems capable of killing people without human input.

Calling the Pentagon's designation of Anthropic as a supply chain risk "baselss and illegal," Lin said national security was "not a blank check to punish and retaliate against government critics."

She said the Defense Department violated the First Amendment with the designation "based on a desire to make a public example" out of the company, adding that while the government was entitled to expect acquiescence when it came to national security, the measures it had taken lacked any "articulable basis."

"Defendants claim that because of Anthropic's 'increasingly hostile manner through the press' and its criticism of the Department of War's views on AI use, Defendants 'cannot trust Anthropic to ensure the integrity of its models.' Neither the Constitution nor the federal statute invoked by Defendants allows them to impose sweeping penalties based principally on Anthropic's critique of the Administration's views," Lin wrote in her decision.

Welcoming the decision, Anthropic told the BBC it was concentrating on "working productively with the government to harness AI for our national security so all Americans benefit from this technology."

Thursday's ruling follows an earlier ruling by Lin in March that directives issued by President Donald Trump and Hegseth ordering the Defense Department and all other government departments and agencies to stop using Anthropic were likely illegal and therefore could not be enforced pending resolution of the case.

The rulings do not require the Pentagon to resume working ties with Anthropic.