A lot of times, this is a necessary thing. If a cat has eaten something that disagrees with it, natural instincts tell it to eat grass in order to purge the offending matter.
However, if your cat does this very frequently, you might consider keeping it inside for an hour or so when you see it trying to eat grass, to prevent it from doing so.
But do keep in mind that if it is only doing this occasionally, that this is very normal, and necessary, for a cat to do.