Depending on where you live, you might be able to attract natural things that get rid of rats.
Making proper roosting for things like owls around the compost pile will allow stalking by birds of prey. I've had limited success in the past, but it can be hard to get consistent avian predators.
The second thing you can do is encourage snakes. This can be hard to do if you live in colder climates, but in warm climates this shouldn't be too hard, especially if you live near a creek or a body of water. There's the risk of cotton mouths taking residence in your yard if you are near a body of water, however cotton mouths, while venomous, are extremely non-confrontational, to the point of absurdity at times. You can poke and prod at them with little recourse, and even when they strike they are likely to leave only dry bites, or not even puncture your skin.
Black water-snakes are typically the snake I see the most that deal with these issues. The nice thing about snakes is that if they kill of all the rats, the snakes won't just leave like a bird, so if your rats return, snakes will likely return very soon after (it can take months to get a bird to take residence in an ideal spot).
Additionally, unlike birds, if rats manage to get into your house, so will the snakes so they can't take refuge in your residence scott free.
The fact that prey will exist in your yard alone will encourage snakes. Some things you can do to further encourage their presence:
put up other sources of food that aren't a nuisance, like birds or bats. You google how to build both bird houses and bat houses on your residence pretty easily. Snakes will eat bird eggs and bird babies, as well as try to snap at bats.
provide unshaded rock/concrete/asphalt platforms for heating during the day. These materials do not insulate heat very well, allowing the snake to heat up faster from sunlight. Such basking opportunities are prime living areas for snakes.
The final thing you can do is not kill snakes. Lots of times people will kill snakes who enter their property due to fear. Simply not killing them is often all it takes for snakes to start patrolling near one's home.
Now building these residences might attract another predator: the domesticated cat. In this case, you've now got a predator that will kill for fun and doesn't depend on rats for survival. The issue with cat's are that, unless they are your cat, you aren't going to have inhouse protection, and you'll have to deal with other cat nuisance stuff (poop, rummaging through gardens, doing weird stuff, being aggressive). Getting your own cat can be ideal, but cats are also not natural predators in most countries, and can hurt native populations of wildlife in ways that natural predators wouldn't, so setting one loose just to take care of rats can pose other issues.