Tuesday’s deadly chemical attack in Syria is a cautionary tale.

The latest horrifying images from Idlib province depict piles of dead children covered in gray dust and sweat, their mouths foaming. Dozens of people were killed by sarin gas, a deadly nerve agent banned under international law.

That ban was extended in 1997 to cover more chemical-weapons-related activity. Syria signed on in 2013.

And yet, the Idlib attack was reportedly conducted by four warplanes. Since the government of President Bashar al-Assad has air superiority in Syrian skies, it’s hard to escape the conclusion that it conducted the horrific attack. (Israeli intelligence sources claim Moscow green-lighted this latest atrocity by Assad, Russia’s ally.)

But wait: Didn’t Syria rid itself of chemical weapons after signing on to the ban? Let’s review.

The watershed moment came during one weekend in late August 2013. Damascus had just crossed President Barack Obama’s famous “red line” by conducting a chemical attack that killed nearly 1,500 people. America, it seemed, was about to jump into the Syrian civil war, if only to punish and deter Assad from crossing that line again.

Then on Aug. 30, a Friday, Secretary of State John Kerry boomed: “History would judge us all extraordinarily harshly if we turned a blind eye to a dictator’s wanton use of weapons of mass destruction.” American, French and British jets warmed their engines.

Then came the U-turn: Over the ensuing weekend, Obama decided his nascent negotiation with Assad’s allies over the Iran nuclear deal was more important than his own red line. The president didn’t want to upset Tehran.

So we didn’t bomb even one remote Syrian sandhill.

Instead, Obama fell for an attractive offer by Russian President Vladimir Putin: Syria would join the international chemical-banning convention and, with United Nations oversight and American financing, it would rid itself of all chemical stockpiles and the means to weaponize them.

Although chemical warfare was cardinal to Syria’s defense doctrine, Obama bought into Assad’s sincerity: A UN-led operation, he believed, would clean Syria of its most dangerous arms without the United States having to fire a single shot.

By September 2014, Sigrid Kaag, the head of a UN committee charged with overseeing the disarming process, declared that 96 percent of Syria’s chemical weapons stockpile was destroyed in the “unique” operation. (Kaag, currently the UN representative in Lebanon, is now rumored to become the next point-woman on the UN-led efforts to find a political solution to the Syria war.)

Meanwhile, history, as Kerry predicted, is still judging us harshly. That’s because Assad continued to attack opponents periodically with chlorine — useful as a toilet cleaner or swimming pool disinfectant, but banned as a war weapon.

And now, sarin. Unlike chlorine, Syria’s sarin was supposed to be destroyed. Except, evidently, it wasn’t. Instead, it was used Tuesday on an Idlib hospital.

“These heinous actions by the Bashar al-Assad regime are a consequence of the past administration’s weakness and irresolution,” the White House said Tuesday. Secretary of State Rex Tillerson said Russia and Iran “bear responsibility” and called on them to “guarantee that this sort of horrific attack never happens again.” But that won’t do.

Even before the attack, UN Ambassador Nikki Haley called Assad a “war criminal,” adding, “Right now, he’s not our No. 1 person to talk to.”

Yet President Trump hasn’t excluded the prospect of negotiations with Assad (though, to be fair, he hasn’t yet presented a strategy for ending the Syrian civil war aside from crushing ISIS).

On the plus side: Despite the political hullabaloo over collusion between Moscow and his campaign, signs are that Trump is cooling off on his early admiration for Putin.

Tuesday’s act may force him to decide. Trump can wash his hands of the whole Syria mess. Or, preferably, he can get the US more involved and thus ensure Washington has a seat at the table for any war-ending talks.

What we can’t do is trust Assad, deal or no deal. That goes for Russia and Iran, too.

Diplomacy with thugs is only as good as the will to enforce it and retaliate when agreements are broken and lines are crossed. It’s a lesson Obama never learned, but Trump must.