You can always simply ask. I have had very good luck with, "Wait, I can't tell if you're being serious right now." Most people will immediately let you know, problem solved.
If the person systematically continues to give sarcastic answers to this question, usually there is something else going on. There may be anger issues, avoidance issues, or social stresses causing the behavior. Depending on the situation, you can again level with them.
In the most extreme cases, something is seriously wrong, and you may have to decide whether you enjoy being around this person or not. It is not your responsibility to fix anyone, but they often appreciate the company.
Good luck, friend!