A public high school teacher in California may not be sued for making hostile remarks about religion in his classroom, a federal appeals court ruled on Friday.

The decision stems from a lawsuit filed by a student charging that the teacher’s hostile remarks about creationism and religious faith violated a First Amendment mandate that the government remain neutral in matters of religion.

The San Francisco-based appeals court said the teacher was entitled to immunity because it was not clearly established in the law that a teacher’s expression of hostility to certain religious beliefs in a public school classroom would violate the First Amendment’s establishment clause.

“We are aware of no prior case holding that a teacher violated the establishment clause by appearing critical of religion during class lectures, nor any case with sufficiently similar facts to give a teacher ‘fair warning’ that such conduct was unlawful,” Judge Raymond Fisher wrote for the court.

As part of its ruling, the appeals court vacated a district judge’s earlier decision that the teacher, Dr. James Corbett, violated the establishment clause in a comment he made in class that creationism was “superstitious nonsense.”

The appeals court side-stepped the question of whether Dr. Corbett’s comment on creationism and other derogatory remarks about religious faith were unconstitutional. Instead, the panel concluded that since Corbett was entitled to qualified immunity it was not necessary for the appeals court to determine whether his comments actually violated the Constitution.

“In broaching controversial issues like religion, teachers must be sensitive to students’ personal beliefs and take care not to abuse their positions of authority,” Judge Fisher wrote.

“But teachers must also be given leeway to challenge students to foster critical thinking skills and develop their analytical abilities,” he said. “This balance is hard to achieve, and we must be careful not to curb intellectual freedom by imposing dogmatic restrictions.”

The dispute began in 2007 when Chad Farnan, then a 15-year-old sophomore in Corbett’s class, took issue with comments about creationism the teacher made during his lectures.

“Aristotle … argued, you know, there sort of has to be a God. Of course that’s nonsense,” Corbett said according to a transcript of his lecture. “I mean, that’s what you call deductive reasoning, you know. And you hear it all the time with people who say, ‘Well, if all this stuff that makes up the universe is here, something must have created it.’ Faulty logic. Very faulty logic.”

He continued: “The other possibility is, it’s always been there.… Your call as to which one of those notions is scientific and which one is magic.”

“All I’m saying is that, you know, the people who want to make the argument that God did it, there is as much evidence that God did it as there is that there is a giant spaghetti monster living behind the moon who did it,” the transcript says.

Corbett told his students that “real” scientists try to disprove the theory of evolution. “Contrast that with creationists,” he told his students. “They never try to disprove creationism. They’re all running around trying to prove it. That’s deduction. It’s not science. Scientifically, it’s nonsense.”

Corbett told his students of a lawsuit in 1994 brought by a high school biology teacher who wanted to teach creationism in the public school system in addition to teaching the required course material on evolution. The courts in that case upheld a school district directive that the biology teacher must not teach creationism in science class.

In the 1994 case, the Ninth Circuit ruled that religious neutrality required that the biology teacher’s positive views of religious ideas must be excluded from public school instruction. But in 2011, a different panel of the Ninth Circuit ruled that the history teacher’s hostile views of religion and faith must be permitted to protect the “robust exchange of ideas in education.”

“Farnan asserts that it has been clearly established for many years that the government must remain neutral with regard to religion, and it may not show its disapproval of religion,” Fisher said.

“This overbroad proposition, cast at a high level of generality, is just the sort of sweeping statement of the law that is inappropriate for assessing whether qualified immunity applies,” the judge said.

Because the law was not clearly established, the panel said, they need not assess the underlying constitutional issue.

“At some point a teacher’s comments on religion might cross the line and rise to the level of unconstitutional hostility,” Fisher wrote.

“But without any cases illuminating the dimly perceived line of demarcation between permissible and impermissible discussion of religion in a college level history class, we cannot conclude that a reasonable teacher standing in Corbett’s shoes would have been on notice that his actions might be unconstitutional.”