SAN FRANCISCO (CN) — A federal judge ruled Monday that the Department of Justice may withhold records on its rules for spying on journalists without a warrant.

The Freedom of the Press Foundation sued the Department of Justice in July 2015, claiming it failed to disclose Freedom of Information Act-requested documents on guidelines for its warrantless surveillance of journalists.

The records were sought after The Associated Press revealed in 2013 that the Department of Justice seized two months of at least seven journalists’ phone records to try to find the source of a leak about a foiled terror plot.

During a hearing in August 2016, a press advocates’ attorney accused the government of purposely hiding records to cover up its failure to bolster press protections, as it promised after public criticism mounted over its seizure of journalists’ phone data.

The press advocates said that the government’s failure to identify a document called Annex G proved its search for requested records was inadequate.

Annex G of the FBI’s 2013 Domestic Investigations and Operations Guide was published by the Intercept in June 2016. The file revealed that FBI agents can seize journalists’ phone records with approval from two internal officials: the FBI’s general counsel and executive assistant director of the FBI’s National Security Branch.

If the purpose of the investigation is to identify a confidential news source, the assistant attorney general for the Justice Department’s National Security Branch must also be consulted prior to approval, according to the leaked document.

In his Monday ruling, U.S. District Judge Haywood Gilliam found the FBI’s failure to include Annex G in its list of responsive documents did not automatically render its search for records inadequate.

“While the FBI’s search may not have been perfect, plaintiff was ‘entitled to a reasonable search for records, not a perfect one,’” Gilliam wrote, citing the Ninth Circuit’s 2015 ruling in Hamdan v. U.S. Dept. of Justice.

Gilliam said he had no reason to doubt an FBI official’s sworn declaration that the bureau conducted a “far more targeted search” in various FBI divisions over a broader period of time than was requested by the press advocates.

Gilliam also found that the government properly invoked exemptions to justify shielding certain files from disclosure.

The withheld files include a policy implementation guide, domestic operations guide, internal emails, draft media guidelines and a PowerPoint presentation on the use of national security letters.

FBI agents use national security letters to get banks, telecom companies, libraries and others to secretly hand over information without a warrant. The use of national security letters was once ruled unconstitutional, but the ruling was stayed and then reversed after a judge found Congress adequately addressed constitutional problems by passing the USA Freedom Act of 2015.

In July 2013, the Department of Justice released guidelines that bar the government from issuing subpoenas to journalists unless high standards are met. But those guidelines did not apply to FBI agents using national security letters to obtain data from companies and institutions without court oversight.

Gilliam accepted the FBI’s assertion that a PowerPoint presentation on the use of national security letters contained legal advice to FBI employees and therefore qualified for an exemption as attorney-client privileged information.

Gilliam also found that draft versions of policy manuals and media guidelines and emails discussing those policies fell within the deliberative process exemption, intended to protect full and frank internal debates about policy changes.

The judge also found that revealing the FBI’s intelligence-gathering methods and sources, which were detailed in seven pages of its domestic operations guide, would cause serious harm to national security.

Gilliam declined to review the disputed files behind closed doors, finding in camera review should be a last resort in national security cases and that it is not necessary in this case due to detailed declarations filed by the FBI.

He granted summary judgment to the Department of Justice and denied it to the Freedom of the Press Foundation.

Department of Justice spokeswoman Nicole Navas declined comment.

Freedom of the Press Foundation executive director Trevor Timm said in an email: “This is an extremely disappointing decision. Whether it’s the Obama administration or the Trump administration, the government should not be able to keep its rules for spying on journalists without a court order secret. It is antithetical to a democracy that supposedly values a free press. We are evaluating our options and will announce whether we will appeal the case soon.”