A Barnstable superior court judge this week sided with the Dukes County sheriff’s office in a spat with Cape and Islands district attorney Rob Galibois over procedures for the release of employee records.

The Hon. Michael K. Callan Wednesday dismissed the DA’s lawsuit against the sheriff’s office. Mr. Galibois had demanded the sheriff hand over 20 years worth of personnel records that he felt may be necessary to go to trial in future cases.

The district attorney is seeking records related to officer misconduct, internal investigations and other documents that could aid a defendant’s case in court. Though some police departments have complied with Mr. Galibois’s request, the sheriff’s department called it burdensome and excessive.

In public statements and court filings, Dukes County sheriff Robert Ogden said he was happy to hand over the exculpatory documents, but on a case-by-case basis, as needed.

In the lawsuit, filed against both the Dukes County and Barnstable County sheriffs, Mr. Galibois maintained the need for 20 years worth of records, known in courtrooms as Brady information after the landmark Brady v Maryland U.S. Supreme Court case that requires prosecutors to turn over exculpatory evidence to defense attorneys.

In the 11-page ruling, Judge Callan agreed with the sheriffs that the district attorney’s request was excessive, and an attempt to compel the sheriffs to do something beyond their mandatory duties when other options, such as requesting documents on a case-by-case basis, were available.

“Instead of seeking exculpatory information from the sheriffs in connection with a specific prosecution, the [district attorney] seeks twenty years’ worth of information for all officers employed by the sheriffs during that time,” Judge Callan wrote.

There is no clear responsibility for the sheriffs to hand over years of records that may not be needed for prosecutions, the judge concluded.

Sheriff Ogden and Barnstable County Sheriff Donna Buckley cheered the ruling this week.

“This decision reinforces our commitment to transparency and accountability within the criminal justice system,” Mr. Ogden said in a statement. “We have always complied with lawful requests for information under the Brady-Giglio line of cases and will continue to do so.”

The Massachusetts Sheriffs’ Association also applauded the court for recognizing the autonomy of sheriff offices.

“Our belief from the onset was that the DA’s request was overreaching and unwarranted,” said Nick Cocchi, president of the association.

A spokesperson for the district attorney said Mr. Galibois is reviewing the judge’s ruling and will decide on how to proceed in the matter.

At a hearing this month, Judge Callan cast doubt on the merits of the case.

“Judges apply law, they don’t make policy,” the judge said. “It just looks to me like these are two different policy approaches to going about the same goal. How do I or some other judge say which policy is better?”