Slavery is not economically viable in most situations. There is a ton of overhead, and like mist institutions, the larger it grows, the more corruption, and the greater amount of financial cost.
So why dies slavery exist at all?
1. The smaller your society, the more likely you will have slavery. The smaller the society, the more oversight, the less corruption, the less waste.
2. Technology very quickly becomes a force multiplier and slavery can only go so far. There are few ways to upgrade a slave without putting the master's life at risk. This could also be applied to advances in magic. So log magic and low science leans towards slavery.
3. Slavery as punishment. If you can't afford to build a prison, makings someone a slave is an excellent alternative.
4. Otherness. If the slaves aren't considered "us" slavery is much easier. The move you relate to a slave, the harder it is to oppress them. Humans can firm bonds with inanimate objects. It us difficult to keep up the hatred of a group indefinitely.
5. Visibility. Slaves should be kept out of sight. Visible slaves need to be treated well. In the south, at most 6% of the population was involved with slaves, and most slaves were treated well for the time, but kept away from everyone else. The larger the population, the more interaction, the more you come to relate to slaves and the more likely it is to end.
So, first determine why you have slaves, then let capitalism do its job. Unfortunately corruption often. Sets in and a dead industry will often work hard to protect itself.
In Brazil, slavery just... died. It was cheaper to just hire people. In America, corrupt people fought to keep it alive to protect their livelihood. In Brazil, the government didn't have an much as a stake as in America.
So we then have the next factor. Is your slavery just a natural part of the economy, or a government run and protected institution. This will change how easily slavery gives up the ghost.
In my setting, slave spells took away people's free will. This resulted in some high profile assassinations ans secual assaults that so disgusted the nobility, they banned all slave spells and made its use punishable by death.
The economy is doing well enough that slavery is mostly gone, but there is a black market for
... specialty slaves... for rich perverts.