If one recited the Amida within four amot of feces, she did not fulfill her obligation, and the Amida must be repeated. Even if she was unaware that there was excrement there, but there was a reasonable concern that the place would contain excrement, she acted negligently by not examining the cleanliness of the place before praying, and therefore she did not fulfill her obligation. However, if the place was unlikely to contain excrement, since she was not required to check, she fulfilled her obligation (SA 76:8; MB 76:31 and 81:13).
The poskim disagree about one who recited berakhot within four amot of excrement. Some say that because she transgressed a biblical prohibition, she did not fulfill her obligation and must repeat all the berakhot (MB 185:7; BHL ad loc.). Others maintain that the Sages are only strict about the recitation of Shema and the Amida, but concerning other berakhot, be-di’avad she fulfilled her obligation (Ĥayei Adam 3:33; Kitzur SA 5:10; Kaf Ha-ĥayim 76:37, 185:14). Since this is a matter of dispute concerning berakhot, and repeating the berakha raises concerns about making a berakha le-vatala, the principle of leniency in matters of uncertainty about berakhot (“safek berakhot le-hakel”) applies, and she may not repeat the berakha. It is best that she meditates on the words of the berakha, for some poskim maintain that one fulfills the obligation to recite a berakha just by thinking it (Rambam), and the prohibition to recite a berakha le-vatala does not apply to thought.