In “Case in Point,” The Marshall Project examines a single case or character that sheds light on the criminal justice system. An audio version of Case in Point is broadcast with The Takeaway , a public radio show from WNYC, Public Radio International, The New York Times and WGBH-Boston Public Radio.

A federal appeals court issued a ruling earlier this month in a Texas case that helps explain why so many prison or jail inmates are sexually assaulted by their guards and why so little is done about it. It’s not just lax training and oversight within facilities. It’s not just poor recruitment practices. It’s also layer upon layer of nearly insurmountable legal standards crafted over time by judges and legislators to protect corrections officers, their supervisors, and, ultimately, local budgets.

Consider the case of Ezmerelda Rivera. In December 2014 she and her husband were arrested for public intoxication and driving while intoxicated. The car was pulled over around 1 a.m. They were taken to the Hale County Jail where they encountered Manuel Fierros, the officer in charge that night. Rivera first was taken by a female guard to change clothes — orange scrubs with no underwear. Then Fierros took over. Now it was about 2:30 a.m. He led Rivera to a room in the jail that he knew was not monitored by video surveillance — a room used by attorneys to talk privately with their clients — where he forced her repeatedly to perform oral sex on him.

They were alone inside that room for nearly one hour. No one came to check on Rivera. She was released the next day. When she filed a complaint with the Texas Rangers she was told that Fierros had confessed to his misconduct. Within days he was arrested and charged with “violating the civil rights of a person in custody through sexual activity,” a felony that carries a two-year maximum prison term. Fierros was promptly released on bail. Nine months later, in August 2015, he pleaded guilty. He was given three years of probation and was able to avoid the requirement to register as a sex offender. Fierros also was barred from serving again as a guard. Rivera, in the meantime, filed a federal civil rights lawsuit against Fierros and his bosses at the jail.

What Rivera did not know when she was taken to that jail is that there were questions about Fierros’ suitability to be a prison guard even before he was hired by Hale County in 2012. After he applied for the job prison officials learned that he twice had been arrested as a 15-year-old for “indecency with a child by sexual conduct.” When they inquired of the local prosecutor they discovered no one knew anything about what had happened to the two cases. But no investigation ensued. Fierros was never tried or convicted nor even asked by jail officials to explain those two arrests. Instead, Fierros was hired and given the standard training all new guards receive — training that included warnings about not sexually assaulting inmates.

What Rivera also did not know when she was taken to the Hale County jail that night is that five months earlier a senior guard at the jail had watched from outside a jail cell as a female inmate performed a sexual act on herself. That episode was caught on the jail’s video surveillance system and the guard was allowed to resign rather than be fired. Jail officials did not change any policies or procedures in response to the incident nor did they require any staff members to undertake any additional sex assault training. Nor did they ensure that all areas within the jail were under video surveillance. Instead, they put up a poster in a room of the jail that said: “Sex with inmates, it’s a felony.”

In short, Rivera’s lawyers told a federal trial judge in March 2015 when they filed suit for money damages, Hale County jail officials knew they had a problem and did virtually nothing to alleviate the risk to inmates like Rivera. The defendants promptly moved to dismiss the case, arguing that the doctrine of “qualified immunity” shielded them from any civil liability. They had done enough, they told the judge, to warrant legal protection. The judge agreed and, on July 6th, so did a unanimous panel of the 5th U.S. Circuit Court of Appeals.

“Qualified immunity” is designed to protect public officials against monetary punishment for mistakes they make in the performance of their duties. Officials can act negligently, even recklessly, toward those in their care without having to pay a price for it. The idea is that public officials, and the local government agencies that employ them, could be rendered bankrupt if they could be successfully sued for every mistake or act of negligence. Immunity today is construed so broadly that it can shield from financial responsibility those who engage in egregious behavior.

If Rivera had been raped by an employee of a department store or a private medical practice the law would have assured her of a more even playing field. Qualified immunity does not extend to private actors (although the Supreme Court ruled five years ago that it can be extended to private citizens who are serving as agents of public officials as they would be in the case of private prison employees). But when a public official asserts the defense of “qualified immunity,” the law puts the burden of proof on the plaintiff. Judges often set up evidentiary standards that are nearly insurmountable for plaintiffs to meet, as the Rivera case helps demonstrate. She sued the guard who sexually assaulted her, his supervisors and the county. The decision rendered by the 5th Circuit focused solely on those supervisors.

(The other parts of the case, against the former guard and the county, still are pending. Because he committed the act in question, Fierros won’t be able to use the same tough standards his supervisors have used).

The first argument Rivera made was that Fierros’ bosses showed “deliberate indifference” when they hired him without adequately investigating the sex crimes for which he was arrested. “Deliberate indifference” exists, the law says, “where adequate scrutiny would lead a reasonable supervisor to conclude that the plainly obvious consequences of the decision to hire would be the deprivation of a third party’s constitutional rights.” There must be, the Supreme Court has added, “a strong connection between the background of the particular applicant and the specific violation alleged.” The adjectives — “adequate,” “reasonable,” “plainly obvious,” “strong” — leave a lot of room for interpretation, and the courts tend to interpret for the defense.

In response to Rivera’s complaint, the 5th Circuit recited a litany of cases in which police or prison supervisors were not held liable even though a “reasonable” person might conclude they had been “deliberately indifferent” in their hiring decisions. A police officer with a criminal record who later used excessive force? Too tenuous a link. A cop who sexually abused citizens during traffic stops and had a pre-employment record of “aggressive” behavior? Too ambiguous a connection. A jailer who forced an inmate to perform oral sex on him had previously been fired by a school district for making improper advances to high school students? “It would have required ‘an enormous leap to connect 'improper advances’ toward female students to the sexual assault,'” the 5th Circuit concluded.

“Fierros’ prior arrests for indecency with a child by sexual contact ‘may have well have made him an extremely poor candidate’ for a position as a jailer,” the 5th Circuit explained, “… but Fierros’ juvenile record provided no clear detail regarding the alleged offenses…it is entirely possible that he was arrested simply for engaging in uncoerced sexual activity with another minor.” A jury “could not find that a plainly obvious consequence of hiring Fierros was that he would sexually assault a detainee,” the court ruled.

The other part of Rivera’s claim focused on the poor training and supervision within the Hale County jail. She alleged that officials should not have continued to allow male guards to take female detainees into rooms without video surveillance. She argued that the lone poster mounted in the jail following the July 2014 sexual misconduct was hardly enough to send a sufficient message to guards. But here, too, the legal standards devised by judges generate near insurmountable obstacles. Plaintiffs like Rivera must prove that supervisors’ “continued adherence to an approach that they know or should know has failed to prevent tortious conduct by employees may establish the conscious disregard for the consequences.” “May” and “conscious” are qualifiers judges lean on to protect public officials.

In response to Rivera’s claims, Fierros’ bosses said that the guard had completed some training, from the Texas Commission on Law Enforcement, and that he had signed a statement in October 2012 in which he affirmed that he understood “there is to be no contact of a sexual nature between myself and any person incarcerated at the Hale County Jail.” This training, alone, was sufficient to protect Fierros’ supervisors. “Simply contending that more or better training would have prevented the assault does not state a claim,” the trial judge in the case concluded. The 5th Circuit agreed, and in doing so shed light on how the law disfavors even those with meritorious claims.

Unlike the trial judge in the case, the federal appeals court ruled that a jury “could conclude” that Hale County officials “did not constitute an adequate response to the serious incident of sexual abuse that had recently transpired in the jail.” But then the judges denied Rivera relief anyway. She did not have a “clearly established” constitutional right to be free from being raped in jail because at the time of her rape her jailers had no reason to know that they had a constitutional duty to provide sufficient training to prison guards. Hale County officials knew or should have known they had to have some training on sexual abuse; they didn’t necessarily know that the training was required to be competent or effective.

The perverse incentives in these immunity cases have become worse over the past 30 years, says Jennifer Laurin, a professor at the University of Texas School of Law. Starting in 1987, she told me last week, the Supreme Court has instructed lower courts to perform the qualified immunity analysis “in a way that takes account of the very particular facts facing officials” and to look backward at what those officials did or did not do. The legal standards create no incentives for prison or jail officials to take specific proactive measures “that courts have not yet considered,” Laurin says, a problem compounded by the lack of clarity judges often give to help officials ensure that they are doing the best they can to prevent future misconduct. “That happened here,” she says. “Even though the judges made very unfavorable comments about the defendants' decisions, it is still not clear — for the next defendants — whether this is unconstitutional.”