Like a lot of star athletes, cyclist Lance Armstrong racked up many a product endorsement deal along with his big wins. But on Wednesday—a week after the U.S. Anti-Doping Agency published a report on allegations that Armstrong was part of a doping ring—his brand-backers started backing away from the seven-time Tour de France champ. Nike, Trek Bicycle, Easton-Bell Sports, and a score of others all bid Armstrong and his tarnished image goodbye.

Endorsement agreements between companies and athletes can be high-risk, high-reward propositions. Corporations are banking on a positive association with the star. Though—as the Armstrong case shows—there’s still plenty of room for things to go wrong. And when they do, says Richard Grant, managing partner of the McGuire Woods Los Angeles office, “it’s critical that the brand be able to take action to protect themselves.”

Cue morals clauses, which can allow companies to terminate an agreement and/or recuperate payments they’ve made to a celebrity or athlete endorser—whether because that celebrity was convicted of a crime, the athlete violated the rules of his or her sport, or the endorser behaved in a way the sponsor found out of line with the brand. “A well-drafted morals clause that sets real clear standards of conduct is probably the best thing you can have in your pocket,” Grant says.

In drafting such a clause, a company or sponsor is on a quest for flexibility, explains Rob Simmons, assistant general counsel at Molson Coors Brewing Company. “The goal is for the sponsor or the company to have unfettered discretion in what may or may not reflect poorly on the brand,” says Simmons, who presented on this topic at the recent Association of Corporate Counsel annual meeting.

But companies should definitely expect pushback from the other side. “It’s strictly a negotiation,” says Arent Fox attorney, Maidie Oliveau, who specializes in sports law. Sponsor companies are trying to narrow down the determination of when a contract can be terminated, while a celebrity or athlete’s agents are examining any measure that could be interpreted as too subjective. “Agents are very, very attentive to morals clauses,” she says.

Which is why it helps to base morals clauses on objective standards—particularly if it’s for an athlete who participates in a regulated sport. “Our feeling is that these standards of conduct should be tied to violations of league or governing body rules,” says Grant. So, for example, if an NBA player is suspended for a certain number of games over an incident, that can serve as a clear trigger for a morals clause.

But even if an athlete violates a morals clause, a company still has to consider its course of action carefully from a business and reputation perspective. Given the conduct that took place, would the company be better off terminating the agreement, or might it generate adverse reaction from customers by doing so?

“The brand has to do a careful balancing act,” says Grant. Just look at Nike and Trek’s decisions regarding Armstrong. On the one hand, both companies decided to distance themselves from the cyclist, but they also reaffirmed their support for his popular namesake foundation, which supports cancer research.

“The Lance Armstrong situation is a real good example of that balancing,” says Grant.

In-house counsel can play an important part in the endorsement process by understanding both what the company expects for its investment and having a practical view of what a celebrity can deliver. “Part of the in-house counsel role is to align the expectations of the company with the ability of the artist or athlete to meet those expectations,” says Simmons.

Counsel must also be sure to speak up for the company’s interests and values. That means the in-house counsel is not there “simply to rubberstamp what marketing thinks is a great idea,” Simmons says. And if you’re mindful of that, hopefully you won’t need to resort to the morals clause down the road.

See also: “USADA Lawyers Speak Out About Armstrong Probe, Pro Cycling’s ‘Omertà,’ “ The AmLaw Daily, October 2012.