Facebook Inc. will no longer allow marketers buying housing, employment and credit-related ads to target ethnic groups, the social-media giant said Friday.

The company has been under pressure from U.S. lawmakers who have raised concerns that a Facebook feature allowing marketers to target users by “ethnic affinity” could be discriminatory.

Facebook said it would build tools to “detect and automatically disable” the use of this type of marketing for some ads purchased on the site. It also will update its ad policies to require advertisers to agree not to discriminate in advertising on Facebook.

“There are many nondiscriminatory uses of our ethnic-affinity solution in these areas, but we have decided that we can best guard against discrimination by suspending these types of ads,” Erin Egan, vice president of U.S. public policy and chief privacy officer at Facebook, said in a blog post.

This is the latest in a string of controversies surrounding Facebook in recent months, centered on how the social network is handling its powerful role as a major source of information for its 1.8 billion monthly users and an increasingly important venue for advertisers. The U.S. presidential election also ignited vigorous debate over whether Facebook’s news feed—a source of news for an estimated 44% of Americans—exacerbates partisan divisions and whether the company was too lax in allowing fake news and misinformation to spread on its platform.