If your compost bin is enclosed, rodents shouldn't be a problem. But, if they've found a way in, it's time to take action.
First, watch what you put in your compost pile. Avoid meat and dairy products, and fatty foods, which tend to attract animals. Other food scraps should be well-concealed beneath a 2 to 3-inch (5 to 8-centimeter) layer of brown materials, such as dry leaves. Turn the materials regularly to prevent nesting and each time you add greens, cover them up with more browns.
Next, examine your bin. Make sure there are no holes or gaps larger than a quarter inch (.64 centimeters). If your bin sits on soil, lay a piece of screen between the soil and the bottom of the bin to prevent rats and other burrowing animals from getting through. A vertical screen inserted 6 to 8 inches (about 15 to 20 centimeters) into the ground around the perimeter of the bin will also help to keep the critters out.