The New York State prison system has for years been among the nation’s worst when it comes to the overuse of solitary confinement. At any given time about 3,800 inmates across the state are held in windowless isolation for 23 hours a day, the vast majority for disciplinary infractions. The average length of a stay in solitary is five months, and from 2007 to 2011, nearly 2,800 people were in solitary for a year or more.

On Wednesday, corrections officials took a major step toward reform by agreeing to new guidelines for the maximum length prisoners may be placed in solitary. The state will also curb the use of solitary for the most vulnerable groups of inmates: those younger than 18 will receive at least five hours of exercise and other programming outside their cell five days a week, making New York the largest prison system yet to end the most extreme form of isolation for juveniles. Solitary confinement will be presumptively prohibited for pregnant women, and inmates with developmental disabilities will be held there for no more than 30 days.

These changes come after a similar reform in the New York City jail system. In January, jail officials announced that they had stopped sending mentally ill inmates to solitary, where they spent an average of nearly eight weeks. Those inmates are now being diverted to psychiatric treatment in jail.

Wednesday’s agreement was the result of lawsuits by three prisoners, one of whom spent more than two years in solitary confinement for filing false legal documents. Those suits are now on hold, and will be settled within two years if two outside experts — one chosen by the Department of Corrections and one by the New York Civil Liberties Union, which is representing the plaintiffs — find that the reform efforts have succeeded. The experts will also issue recommendations on the role of solitary confinement in the prison disciplinary system.