A state judge ruled on Wednesday that a reporter for The New York Times could not be forced to testify at a pretrial hearing about her jailhouse interview with a man accused of killing the toddler known as Baby Hope.

In a one-page ruling, Justice Bonnie G. Wittner of State Supreme Court in Manhattan said the reporter, Frances Robles, was protected by New York’s shield law. Justice Wittner quashed two subpoenas from the Manhattan district attorney’s office ordering Ms. Robles to testify and to turn over her notes from an interview at Rikers Island with Conrado Juárez, in which he denied killing 4-year-old Anjélica Castillo in 1991.

“New York law recognizes that the proper role of journalists is out reporting stories, not serving as witnesses in court cases,” said David McCraw, assistant general counsel for The New York Times Company. “The court’s decision underscores that the public interest is best served by protecting reporters from unnecessary subpoenas.”

Justice Wittner wrote that the district attorney’s office had not shown that its case would rise or fall on Ms. Robles’s testimony and her notes, as the shield law says it must in order to compel a journalist to take the witness stand. But the judge left the door open for prosecutors to argue again at trial that Ms. Robles’s testimony was critical to their case.