A school police officer handcuffed a sobbing 7-year-old boy for refusing to go to the principal’s office. On Thursday, the Court of Appeals for the 8th Circuit said the officer didn’t violate any constitutional rights at all.

The decision came down hours after Democratic presidential candidate Julián Castro drew applause for pledging to “end qualified immunity for police officers so that we can hold them accountable for using excessive force.” Castro zeroed in on the doctrine of qualified immunity as a major tool that shields cops from consequences for virtually any behavior, even when they violate constitutional rights. Like clockwork, federal courts invoke qualified immunity to toss lawsuits against officers who engage in egregious and often brutal conduct. Two appalling cases in the past few weeks illustrate his point.

K.W.P v. Kansas City Public Schools, Thursday’s decision, revolves around Kalyb Wiley-Primm. Primm, who is black, was being teased and bullied by a classmate. He stood up, cried, and yelled, prompting a school staff member to tell him, “You better sit down. You are about to get in trouble.” A staff member asked Brandon Craddock, a school patrol officer, to assist with an “out-of-control” student. By the time Craddock arrived, Primm had sat back down in his seat.

Craddock asked Primm to walk with him into the hallway. On the second request, Primm complied. Craddock then tried to take him to the principal’s office, but Primm refused and tried to walk away. After telling Primm “several times to stop walking away,” Craddock grabbed his wrist. Primm tried to pull away, and Craddock handcuffed him. The officer then sat Primm in the front office for 15 minutes. After his father arrived, Craddock removed the handcuffs. Primm had been in the cuffs for a total of 20 minutes; they left his wrists sore and red.

To reach this conclusion, Smith made Primm sound like a violent felon on the lam rather than an emotionally distraught 7-year-old.

The ACLU sued Craddock on behalf of Primm, alleging that he had violated the student’s Fourth Amendment right to be free of excessive force and unreasonable seizures. Craddock claimed qualified immunity, a doctrine that insulates officers from lawsuits. Under this rule, the police cannot be sued unless they infringe upon a constitutional right—and that right is “clearly established.” A constitutional right is only “clearly established” if a reasonable officer would know that it is protected by binding precedent.

A federal district court initially denied Craddock’s claim to qualified immunity, allowing the case to go to trial. The court found that the officer had violated Primm’s “clearly established” Fourth Amendment rights. But on Thursday, the 8th Circuit reversed this in an opinion by Judge Lavenski Smith, joined by Judges William Duane Benton and David Stras. (Smith and Benton were appointed by George W. Bush; Stras was appointed by Donald Trump.)

Many civil rights plaintiffs trip up on the second prong of the qualified immunity test: Courts frequently rule that, yes, an officer may have violated a constitutional right, but that right was not “clearly established.” Smith’s opinion went further: He held that Craddock did not violate Primm’s rights at all. Under Supreme Court precedent, an officer violates the Fourth Amendment when he uses excessive force that is “objectively unreasonable,” or detains a student in a manner than is unreasonable “under all the circumstances.” Smith found that Craddock’s actions were reasonable under either standard and thus constitutional.

To reach this conclusion, Smith made Primm sound like a violent felon on the lam rather than an emotionally distraught 7-year-old. Primm “attempted to flee from Officer Craddock upon his removal from the classroom,” the judge wrote, and “his escape efforts posed a safety risk to himself.” A “reasonable officer,” he continued, “could have concluded” that Primm’s “admitted conduct” constituted “an act of violent resistance.” Moreover, Craddock’s decision to keep Primm handcuffed for 15 minutes while he sat quietly in the front office “was a reasonable course of action” because it may have been necessary to prevent the student “from trying to leave and posing harm to himself.”

Just for good measure, Smith added that even if the reasonableness of Craddock’s actions was “questionable,” he still deserved qualified immunity. Why? Because it is not “clearly established” that handcuffing a small child for 20 minutes is unconstitutional. There is no precedent from the Supreme Court or the 8th Circuit explicitly outlawing this practice. Thus, Craddock is shielded from legal repercussions.

How did the court’s analysis go so awry? In part, by refusing to take Primm’s age into account. Throughout his opinion, Smith wrote that Primm “admitted” to incriminating conduct when he testified about the incident. For instance, Smith asserted that Primm “admitted” to getting “more upset” after Craddock cuffed him, leading him to “tr[y] to get away.” Primm’s resistance, Smith explained, contributed to the “reasonableness” of Craddock’s decision to keep him cuffed.

Really? A 7-year-old got “upset” after a male officer walked into his classroom, took him into the hall, and handcuffed him? And his distress gave the officer an even better reason to keep him cuffed? It is hard to see how Craddock’s intervention was a “reasonable” reaction to a small child’s emotional outburst in response to a determined bully. At every turn, the officer exacerbated the encounter, allowing a 7-year-old’s meltdown to escalate into a forcible arrest.

Qualified immunity encourages this style of reckless policing. A ghastly decision out of the 11th U.S. Circuit Court of Appeals, Corbitt v. Vickers, illustrated this point in July. The case began as a manhunt for Christopher Barnett, a criminal suspect, in Georgia. Barnett “wandered” into someone’s yard, where an adult and six children were playing. Multiple police officers entered the yard and demanded that everyone—including two children under the age of 3—get on the ground. Barnett, too, complied, and was visibly unarmed.

One officer, Michael Vickers, then saw the family dog, who was not at all aggressive and posed no threat. Vickers nonetheless attempted to shoot the dog. One bullet missed the dog but struck a 10-year-old child in the knee. Vickers’ victim was just 18 inches away from his weapon. The bullet shattered the child’s knee. His family sued Vickers for violating his constitutional rights.

By a 2–1 vote, the 11th Circuit granted Vickers qualified immunity. Judge R. Lanier Anderson, a Jimmy Carter nominee, wrote the majority opinion, which was joined by Judge Elizabeth L. Branch, a Donald Trump nominee. Judge Charles R. Wilson, a Bill Clinton nominee, dissented.

Anderson wrote that Vickers did not have “fair warning that his particular conduct violated the Fourth Amendment.” The victim “was not the intended target of Vickers’s gunshot,” Anderson explained. And no Supreme Court precedent explicitly states that an individual “suffers a violation of his Fourth Amendment rights when an officer shoots at a dog—or any other object—and accidentally hits the person.” Instead, precedent suggests that “a Fourth Amendment violation occurs only when [an officer] intentionally targets the person” he shoots. Because “there is no clearly established right to be free from the accidental application of force,” Anderson awarded Vickers immunity from suit.

The ruling in Vickers is preposterous; it makes a mockery of the constitutional rights at stake. Craddock and Vickers will receive impunity due to the perversion of federal law that gave rise to qualified immunity in the first place. The statute that allows individuals to sue abusive officers, Section 1983, says nothing about “clearly established” law; rather, it states that officers “shall be liable to the party injured” when they violate civil rights. The Supreme Court made up the “clearly established” rule out of whole cloth when interpreting the law. In doing so, it contributed to what Justice Sonia Sotomayor has decried as the “ ‘shoot first, think later’ approach to policing.”

Congress is free to amend the law at any time to overturn the Supreme Court’s distortion of Section 1983. That seems to be what Castro has in mind: His People First Policing plan calls on Congress to “reform and restrict” qualified immunity, though on Wednesday he said he wanted to “end” it altogether. Castro could put more flesh on the bones of this proposal, but he has the right idea. The parade of egregious qualified immunity decisions from federal courts has drawn opposition from a cross-ideological coalition of civil liberties groups. Reining in or abolishing the doctrine should be popular across the political spectrum. Cases like K.W.P. and Vickers illustrate the urgency of the crisis. Until Congress puts a stop to this madness, qualified immunity will continue to prevent victims of police brutality from obtaining a semblance of justice.