Immigration agents who turn up at New York City public schools will be turned away unless they have a court-ordered warrant, Mayor Bill de Blasio said Tuesday.

“If [immigration] agents come to a school, they will be kept outside the building while the school staff assess the situation, get NYPD assistance and consult with appropriate city legal authorities,” the mayor said at a press conference about the new policy.

“They can’t blow by our security. They have to follow our rules.”

But the US Immigration and Customs Enforcement agency told The Post the guidelines aren’t necessary because “sensitive locations” such as schools and churches are generally off limits already.

“The ICE sensitive locations policy, which remains in effect, provides that enforcement actions at sensitive locations should generally be avoided, and require either prior approval from an appropriate supervisory official or exigent circumstances necessitating immediate action,” ICE spokeswoman Rachael Yong Yow said.

She added that the feds want to ensure that “people seeking to participate in activities or utilize services provided at any sensitive location are free to do so without fear or hesitation.”

Although NYPD school safety officers already check identification for all visitors, de Blasio said no such guidelines currently address ICE agents.

If agents can’t provide warrants signed by a judge, they won’t be allowed in, he said.

De Blasio conceded there have been no incidents of immigration agents trying to enter schools.

Councilman Joe Borrelli (R-SI) said that “perhaps the mayor should go further and allow Staten Islanders to exempt themselves from the city rules . . . that we would prefer not to follow — but that’s unfortunately not how laws work.”