SAN FRANCISCO (AP) — Google must comply with the FBI’s demand for data on certain customers as part of a national security investigation, according to a ruling by a federal judge who earlier this year determined such government requests are unconstitutional.

The decision involves “National Security Letters,” thousands of which are sent yearly by the FBI to banks, telecommunication companies and other businesses. The letters, an outgrowth of the USA Patriot Act passed after the Sept. 11 attacks, are supposed to be used exclusively for national security purposes and are sent without judicial review. Recipients are barred from disclosing anything about them.

In March, U.S. District Court Judge Susan Illston sided with the Electronic Frontier Foundation in a lawsuit brought on behalf of an unidentified telecommunications company, ruling the letters violate free speech rights. She said the government failed to show the letters and the blanket non-disclosure policy “serve the compelling need of national security” and the gag order creates “too large a danger that speech is being unnecessarily restricted.”

She put that ruling on hold while the government appeals to the 9th U.S. Circuit Court of Appeals.

In the latest case, Illston sided with the FBI after Google contested the constitutionality and necessity of the letters but again put her ruling on hold until the 9th Circuit rules. After receiving sworn statements from two top-ranking FBI officials, Illston said she was satisfied that 17 of the 19 letters were issued properly. She wanted more information on two other letters.

It was unclear from the judge’s ruling what type of information the government sought to obtain with the letters. It was also unclear who the government was targeting.

Kurt Opsah, an attorney with the Electronic Frontier Foundation, said he was “disappointed that the same judge who declared these letters unconstitutional is now requiring compliance with them.”

Illston’s May 20 order omits any mention of Google or that the proceedings were closed to the public. But the judge said “the petitioner” was involved in a similar case filed on April 22 in New York federal court.

Public records obtained Friday by The Associated Press show that on that same day, the federal government filed a “petition to enforce National Security Letter” against Google after the company declined to cooperate with government demands.

Neither Google nor the FBI would comment.

The letters issued by the FBI can be used to collect unlimited kinds of private information, such as financial and phone records. The FBI sent 16,511 letters requests for information regarding 7,201 people in 2011, the latest data available.

Critics contend the government is overly zealous in using the letters, unnecessarily infringing on privacy rights of American citizens. In 2007, the Justice Department’s inspector general found widespread violations by the FBI, including sending demands without proper authorization. The FBI has since tightened oversight of the system.