On Friday, Shkreli was sentenced to seven years in prison for committing fraud. In 2015, Shkreli made headlines after he raised the price of a life-saving drug for patients with AIDS by 5,000 percent—a move that earned him the title of “the most hated man in America.”

Prosecutors had sought a sentence of at least 15 years; the defense had pushed for 12 to 18 months.

… His fraud convictions were unrelated to that episode, stemming instead from his involvement with Retrophin, a pharmaceutical company he founded in 2011, and two hedge funds he ran.

Though Shkreli definitely could have used good PR advice (had he listened to it), his trial over the last two and a half years provides several crisis lessons for communicators.

Consider these insights:

1. A sincere apology and restitution can do wonders—except when it’s too late.

In February 2016, Shkreli’s actions during a congressional hearing over raising Daraprim’s pricing drew scathing remarks on social media—and his demeanor didn’t change much as he was arrested for, then tried and convicted of, securities fraud.

2. In the court of public opinion, the legal way isn’t always the right way.

Though his trial was due to fraud charges unrelated to hiking the price of Daraprim, some speculate that Shkreli thrust himself into the spotlight with his decision to raise the drug’s price and his resulting bravado, making himself an easier target for legal recourse.

Besides a criminal trial, he also faced waves of criticism for his mocking attitude. Up until the sentencing, Shkreli maintained his derisive attitude.

“The attempt to public shame is interesting,” says Shkreli. “Because everything we’ve done is legal. [Standard Oil tycoon John D.] Rockefeller made no attempt to apologize as long as what he was doing was legal.” In fact, Shkreli says, he wishes he had raised the price higher. “My investors expect me to maximize profits,” he said in an interview in early December at the Forbes Healthcare Summit, after which Forbes contributor Dan Diamond summed up Shkreli as “fascinating, horrifying, and utterly compelling.”

Though your actions might be free from legal consequences, remember that the court of public opinion is always in session. Crises can happen in a matter of minutes, and most people will care more about how your empathy and compassion than whether you followed the letter of the law.

Even after his arrest in 2015, Shkreli went against his lawyers’ advice to lay low by taunting authorities in Facebook posts. And after his conviction last year, the judge revoked his bail and jailed him when he said he would pay a $5,000 bounty to anyone who could get a lock of Hillary Clinton’s hair while the Democrat was on a book tour.

Shkreli’s defense attorney argued that the post was satirical and should be protected under free speech, but Matsumoto called Shkreli’s Facebook post a “solicitation of an assault” rather than a protected political statement.

“The fact that he continues to remain unaware of the inappropriateness of his actions or words demonstrates to me that he may be creating ongoing risk to the community,” said U.S. District Judge Kiyo Matsumoto, in revoking his bond.

Though you might not receive the same punishment as Shkreli with a controversial Facebook post or series of tweets, the consequences to online rants can be severe.

Many have lost their jobs or tarnished either their own or their organizations’ reputations when they mouth off online. Others have experienced backlash years later when racist tweets have been dug up and splashed across news outlets’ headlines.

From posting pictures of you partying too hard to using questionable language to voice your opinion, take care that your actions online don’t affect your career and reputation offline.

4. Be prepared for the worst—and don’t expect to get off easy in a crisis.

In August 2017, Shkreli was acquitted of five counts of conspiracy, but jurors found him guilty of two counts of security fraud and one count of conspiracy. Shkreli soon acted as if he won the case.

Shkreli, who has been known to livestream on YouTube, went online to answer people's questions about the trial once he got home from court.

During the live video, Shkreli said that he believes "there's a good chance that there's no jail sentence at all" and said he might appeal. But, he added, if he were sent to prison, it would be for less than a year and he expected to spend it at a minimum security prison — or "club fed" as he called it — where he would spend his days playing tennis and video games. He said "Big Rolls" would be his prison name.

You don’t have to be sentenced with seven years in prison to learn the importance of playing it safe and bracing yourself for the worst: It’s better to prepare for potential crises than be surprised by unexpected backlash and more.

PR pros should create (and regularly review) crisis plans well in advance of any sticky situations, helping all members of the organization know what their responsibilities are when a crisis hits.

The advice to play it safe can be directly applied to remarks, too: Though confidence is often a positive trait, you don’t want your organization or executive to come off as boastful or arrogant. Instead, be as realistic and transparent as possible, and keep your words succinct.