Her experience in jail would have been awful even if she’d been a convicted criminal. But she wasn’t—she was a rape victim who had been incarcerated by a prosecutor worried about the possibility of her not showing up to testify at trial against her attacker. Thanks to a little-known legal instrument known as an “attachment order,” the district attorney in Harris County, Texas, forced the woman to spend an entire month in a notoriously hellish jail despite not even being accused of a crime—all because he feared that she would fail to appear at a court date during which she was supposed to provide testimony against a now-convicted rapist. During her time in the jail, according to a lawsuit filed earlier this month, she was beaten by a fellow inmate, treated like a sex offender by medical staff, and punched in the face by a guard.

The woman, who has been identified in a recent investigation by news station KPRC as “Jenny,” was originally supposed to testify in the rape case against Keith Hendricks on Dec. 8, 2015. But her testimony was interrupted when, according to her lawsuit, she had a “mental breakdown” on the stand. The judge in the case ordered a monthlong recess on account of the approaching holidays, and Jenny was taken to a hospital for evaluation and treatment.

As detailed in the KPRC investigation, it was during Jenny’s stay at St. Joseph Medical Center that prosecutors received clearance from a judge to detain her after her discharge. When Jenny checked out of the hospital on Dec. 18, an armed investigator with the Harris County DA’s office showed up and arrested her, placing her in handcuffs and transporting her to the Harris County Jail.

According to Jenny’s lawsuit—which names the assistant DA who secured her detention as a defendant, along with the county sheriff and the county itself—the court order that resulted in her incarceration was “unauthorized” because she had not been subpoenaed and lived outside the jurisdiction of Harris County.

While attachment orders, or “witness bonds” as they are also known, are sometimes used around the country for legitimate purposes, they are supposed to be invoked when a material witness under subpoena is considered a flight risk: According to Jenny’s lawyer, Sean Buckley, they are usually reserved for cases involving illegal immigrants who might be scared to testify out of a fear of deportation, people who are considered co-conspirators of the defendant, and suspected gang members.

The woman in this case, to reiterate, was a rape victim with a mental illness. According to the suit, however, that did not stop jail staff from classifying her in their computer system as a defendant in a sexual assault case—an oversight that later led medical staff to question her “orientation” to reality and to note her “confused” belief that she was a victim rather than a perpetrator. To make matters even worse, Jenny was placed in general population rather than in the jail mental health ward—a “deafening environment swarming with hostile, predatory, and violent inmates and convicts, and overseen by callous, understaffed, and impatient jail guards,” according to the suit.

The suit details two physical assaults the woman endured while locked up at the jail: The first allegedly came at the hands of an inmate who slammed her head against the floor, and the second was the result of an altercation with a jail guard who punched her with a closed fist while she was having an “acute psychiatric episode.” That guard, who is named as a defendant in the suit, later asked the district attorney’s office to press felony assault charges against Jenny—a request that was, shockingly, granted. Though the charges were eventually dropped, it was not until about a week later, meaning that Jenny had to spend an extended period of time living in fear of a possible 10-year prison sentence.

It was not until Jan. 11, about three weeks after her incarceration, that Jenny was brought to court to testify in the rape case. According to her lawyer, she had to appear wearing clothing lent to her by prosecutors—a “humiliating” ensemble that included a pair of jail-issued rubber orange shoes. Three days after she appeared on the stand, she was finally released from jail. Her rapist, meanwhile, was convicted and given two life sentences.

The Harris County prosecutor’s office did not respond to a request for comment. However, district attorney Devon Anderson earlier issued a video statement on Facebook in response to the KPRC investigation, in which she stated there were “no apparent alternatives” that would have guaranteed “the woman’s safety and her appearance at trial.”

Anderson said her office was compelled to use an attachment order in this case because the woman called to testify was homeless and mentally ill. “If nothing was done to prevent the victim from leaving Harris County in the middle of trial,” she said, “a serial rapist would have gone free.” Anderson also stated that Jenny had indicated she was unwilling to testify again.

Buckley, the woman’s lawyer, told KPRC that Jenny was not in fact homeless and that Anderson should have known that because “her investigators were the ones who went there to pick Jenny up at her apartment and bring her to Houston to testify.” He told the New York Times that while it was true his client had indicated she might not testify a second time, she did so “while she was having a mental breakdown.”

Jenny’s living arrangements don’t matter. Someone who hasn’t been accused, let alone convicted, of a crime should not have to spend time in jail—especially if they are known to have a mental illness. If it’s true that the prosecutor’s office has no alternative, as Anderson suggested in her video statement, that’s a problem. Incarcerating an innocent should not even be an option.