Spoilage automatically generates a trash slot; the issue is you're not spending fast enough. In this case you would filter the inserter to only pick up the non-spoiled item. Once it spoils, the inserter will be forced to drop it when there's room on the output (belt, chest, etc) and then you deal with the trash.
Amendment, only machines that are fueled by spoilable items generate a trash slot. But still in that case just add another inserter that checks for spoilage.