The Shulhan Aruch (Orah Haim 172:1) rules that if one had a liquid in one’smouth and realized that a blessing was not recited before drinking it, one can swallow the liquid. Since the rabbis were concerned that spitting out the liquidwhen one remembered that a blessing was not recited would lead to a waste of that beverage, they permitted one in this situation to go ahead and swallow that liquid. The Biur Halacha (ibid.) mentions that this Halacha applies only if thereis no other drink available. If another drink, or more of the original, is available,one should recite a blessing and drink some so as to exempt what was consumed beforehand. This is also the opinion of Rabbi Ben Zion Abba Shaul (Or LeZion, vol. 2, § 46:12).
With regards to solid food, one should remove the food from one’s mouth and then recite the appropriate blessing. If this proves too repulsive, one can movethe food to the side of one’s mouth and recite the blessing. If both of these solutions are not practical, then one may swallow the food. Ideally, however, one should not have food in one’s mouth while reciting a blessing. This is based on the the verse (Tehilim 71:8) says “My mouth will be filled with Your praise”, which implies that when reciting a blessing, one’s mouth should only be filled with praise for Hashem and nothing else.
There is an apparent contradiction involved in the aforementioned situations; on one hand, spitting out the contents of one’s mouth may result in the loss of otherwise good food or drink. On the other hand, the Gemara (Berachot 35a) compares eating and drinking without a blessing as a form of stealing from Hashem, as it were. Rabbi Shlomo Zalman Auerbach reconciles this by explaining that the prohibition of consuming food without a blessing applies only to one who is obligated in that blessing. Once someone has the food or drink in one’s mouth and cannot practically recite a blessing, the obligation to recite a blessing no longer applies to that person. As such, one may forego the blessingand swallow what was already in one’s mouth.
Summary: One may swallow the liquid contents of one’s mouth if oneforgot a blessing provided that there is no additional drink available. Onemay swallow solid food provided that one cannot remove it from one’s mouth or move it to the side of one’s mouth and then recite the blessing.