In a win for freedom of the press, a federal court this month struck down an Iowa law making it a crime to lie about your intentions when accessing an agricultural production facility.

The “ag-gag” law, which was aimed at undercover journalists and activists, essentially prevented undercover investigations of the agricultural industry. In a lawsuit brought by the ACLU of Iowa, the court rightly found that the law violates the First Amendment.

This welcome ruling joins a host of other court decisions finding similar laws in other states to be unconstitutional — and for good reason. Undercover reporting is a critical tool to inform the public about corporate wrongdoing. Overbroad laws criminalizing false speech violate the First Amendment and prevent investigative journalism from holding powerful private actors to account.

Iowa was one of many states that passed ag-gag laws criminalizing various activities essential to undercover investigations aiming to expose animal cruelty and other illegal or unsafe activities. These laws were passed after several high-profile undercover investigations revealed various abuses, such as sick cows being repeatedly shocked with electric prods in California and young calves being kicked and skinned alive at a Vermont slaughterhouse. Such investigations have prompted large-scale meat and egg recalls. That is why the ag-gag laws sparked opposition from press freedom and civil liberties groups as well as animal rights, environmental justice, and food safety advocates.

One major area of constitutional concern is that ag-gag laws often make it a crime to be untruthful when gaining access to an industrial farm or similar place — for example, by not disclosing that you are an investigative journalist or activist when applying for a job.

Why is it a constitutional problem to outlaw lying? Because the First Amendment protects false speech where there is no legally recognizable harm. The Supreme Court has held that while certain limited categories of false speech, such as perjury, are inherently harmful and can be outlawed, the First Amendment does not permit outlawing all lies — even distasteful lies that have no social benefit.

When it comes to undercover investigations, however, lying is done in service of the public good — and not only in the agricultural industry. The enforcement of anti-discrimination laws, for example, has long relied on undercover audit testing of landlords and employers to ensure they do not treat housing or job applicants differently based on protected class status such as race, gender, or disability.

Such testing often requires false speech, for example when submitting identical, false resumes to an employer that vary only by the name of the applicant, or when a housing tester misrepresents her intention to actually rent a home. The federal government and the courts have recognized for decades that these tactics are a critical part of upholding civil rights protections.

In a similar vein, the ACLU is currently representing researchers who are asserting their First Amendment right to submit false information online as part of testing websites to uncover algorithmic discrimination in housing and employment opportunities. That is why it is encouraging that the court considering the Iowa law concluded that there are constitutional problems with outlawing false speech in service of undercover journalism. Courts have also struck down ag-gag provisions prohibiting recording or collecting information in Idaho, Utah, and Wyoming on First Amendment grounds.

Efforts to criminalize such undercover investigations insulate private actors from being held publicly accountable. They also violate the First Amendment.