Yesterday, the North Carolina Supreme Court considered whether immigrants detained unlawfully under state law by state officials can challenge their detention in the state’s courts.

The lower court previously said no, breaking with every other state in the country that has faced a similar challenge and leaving more than 4,000 people in North Carolina at risk of illegal detention every year.

North Carolina’s top judges can now reverse course and ensure that the state’s lawful permanent residents, refugees, DACA recipients, international scholars, and foreign-born technology, healthcare and agricultural workers are not detained in our jails, in violation of our laws, without recourse to our courts.

There are good reasons for the state supreme court to do so. First, federal immigration agents routinely ask North Carolina’s sheriffs and police officers to hold immigrants in county jails based on their suspicion that the individuals have run afoul of the country’s civil immigration laws. But the databases that immigration officials rely on and the detention requests they issue to state and local officers are riddled with errors. A database in California used to check whether an individual has violated immigration law is so faulty that a federal court has prohibited law enforcement officers across the country from holding anyone based on a detention request issued by that office.

Separately, press accounts have revealed that thousands of requests sent to local police and sheriff’s departments were defective, unbeknownst to the local officials who enforced them. In multiple immigration offices, the forms that are supposed to identify specific people suspected of an immigration violation were instead left blank and signed and distributed in bulk. Erroneous requests have also led to the prolonged detention of U.S. citizens in local jails.

Evidence of these errors are present in the case facing the state supreme court. According to court documents, the Mecklenburg County sheriff’s department held one immigrant in its jail based on a request that identified a different person; another immigrant was held in the same jail on the basis of an unsigned form, meaning no immigration official had verified the person was suspected of an immigration violation at the time the sheriff’s department agreed to detain him. Despite the potential for errors like these to result in unlawful detention in North Carolina jails, the lower court decision prevents the state’s immigrants from raising these problems in local courts.

Additionally, state courts in Massachusetts, Colorado, New York and Minnesota have found that local law enforcement officers’ practice of holding people for civil immigration reasons can violate state law. The laws in these states are similar to those of North Carolina, which draw clear limits around the powers of police officers and sheriff’s deputies to arrest and hold state residents.

Research I published this summer traces these state laws back to the founding of our country. For centuries, state and territorial sheriffs have been constrained in their authority to arrest and hold the people they police. We imported this tradition from England as a way to maximize individual freedom and ensure that officers could deprive people of their liberty only after review by a court, with narrow exceptions to pursue criminals and suppress riots.

Immigration officials, in contrast, do not have a court order when they ask local police officers to hold people on their behalf, nor are they enforcing criminal laws. Traditional constraints on local officers to arrest people without a criminal basis were particularly strict and limited to carrying out court orders or in specific circumstances provided by the state’s legislature. These historical limits on local arrest power persist in state laws across the country today and have led to multiple decisions recognizing the unlawful detention of immigrants by state officials.

North Carolina, however, has become an outlier. Immigrants residing here and held by local officers have no clear way to enforce these long-standing state laws. State officials have no assurance that the proper person is identified and that the accusations are valid. State courts no longer have the power to protect immigrants living in North Carolina from unlawful arrest. The North Carolina Supreme Court now has the opportunity to rectify this situation.

Kate Evans is a clinical professor of law and director of the Immigrant Rights Clinic at the Duke University School of Law.