I have outlined a very general case for vanilla mob grinders and such below from my own experience, but you want a sorting system that detects the item inside and either drops the item in or leaves it out. You would probably want to watch Sethbling's video he did on his automatic sorting system on the mindcrack server. His answer to your problem is better in your case (although I believe it is similar to my own):
A Very General Solution to your problem:
Put a different item that will not be processed in the hopper into each of the spaces of the hopper or chest you are trying to not use. That's a bit unclear, so I'll give an example.
For example, if you were doing a skeleton grinder farm, and you only wanted 2 spaces of chest for bones, you would put two bones in the chest, and fill up the rest of the spaces with a piece of dirt, or something you expect not to go into the chest, like one mossy cobble in all spots you don't want to use. Then go to the one hopper that leads to the chest and fill up all its spaces, but one, with another material that isn't dirt or bones, for example, cobblestone. This is to prevent the cobblestone from going into the chest, and let the hopper pick up only bones. If the skeleton drops anything other than bones, it will not be picked up by the hopper, unless the hopper runs out of bones to process, and then might pick up arrows.
Please leave feedback about this answer in the comment section below. Hope it helps!