Sour flavors can sometimes creep up in a homemade beer. There are only a few beers that taste good with sour flavor. Sour flavor can arise due to various reasons. The most common reason is bacterial infection. Lactic acid is a souring agent that adds a typical sourness to the beer. If you do not pay close attention to sanitization, your beer might get infected by microbes and become sour. So if your beer ends up tasting sour, you need to check your sanitization processes and make sure you do not allow air to be in abundant contact with the beer once fermentation has started. Another common reason for sourness in beer is yeast infection. We're not talking about beer yeast here, but rather Brett (Brettanomyces), a type of yeast that causes a sour flavor in beer. It is sometimes added to certain beer styles for its fruitiness. Available as liquid yeast culture, it can be used to make sour and fruity beers. But you must make sure that its quantity is limited otherwise the homebrew will become too sour. Yeast infection can also happen due to unsanitary conditions, so make sure that you properly sanitize all equipment before using it. If you are getting bitter, grainy, or astringent flavors in your home brew beer, it might be called a sour-off flavor. Again, these might be the result of poor sanitization. You need to make sure of the hygiene while cooling your wort, during fermentation, while adding ingredients, sampling/measuring, and bottling the beer. How do you prevent sour flavors? Just keep everything sanitized. You need to clean your home brewing equipment thoroughly before using it. Purchase a strong sanitizer and clean everything that is going to touch your beer. A couple of sanitizers on the market for this purpose are: Basic A and Iodophor. Even if you intentionally want to add sour flavor, you need to use clean home brew stuff. It is best to stick to special bacteria/yeast, and follow proper sanitization methods because lack of hygiene can result in really low quality beer. Another blog post that may be of interest is "The Import Role Yeast Play In Brewing Beer". This post goes over the critical part beer yeast play in brewing a beer.