Sometimes, children or teenagers verbalize out-loud these negative self-talk in order to seek for attention. Still, we need to find what is the real reason they think they don't have enough attention, or what is really bothering them. In case this self-criticizing comments are aiming at manipulating the parents and filling them with guilt, so that the children can skip punishment or ask for extra privileges, then staying calm and firm is the response they are least expecting. Make them aware that you are there to support them, but still they should realize their own responsibilities. Moreover, keep in mind that after an outburst like that, parents tend to be more soft and compromising, and the children know that and they are using it.
However, being harsh on themselves is something that children didn't consciously choose for themselves. It is a behavior displayed already by one or both parents, and the children are simply following the pattern. A "must-be-perfect" mother who tries to excel in her multiple roles as a mother, as a wife, as a daughter, as a businesswoman, etc, and all they hear from her is rules for organizing and "I don't have time for that". Or a "must-be-the-best" father who asks for his children's grades or school performance every day, who doesn't praise them for their efforts but only when the results are worth it, or who has given up on them because they didn't manage to reach his high standards, who reminds them often of what he went through and he has still been doing for them, so they should appreciate it by trying their best at school. When the children are harsh on themselves, their parents have been doing the same for a long time.
No reason to panic. Once more, parents don't need to be perfect. Trial and error is the most humane thing in the world, so by showing to the children that even if you have overseen something, you are there to correct it, you release them of a big burden of this perfectionism obsession. Your aim is to help them be strong and self-confident, so that they can defeat this negative self-talk by themselves, without needing the praise of others.
A little bit of reality check can help avoid the big dramas. "Has it happened before?", "Is it something that we can correct?", "How realistic were your expectations?" are some questions that can put the self-talk in the right perspective. Parent's don't need to go from one extreme to the other, that is from over-criticizing to over-praising, since the children can perceive that this is a panic reaction and an easy way out. Just say things as they are: "Yes, I can see there is some chance of falling, but I can also see some chance of succeeding, if....".
Make them see the Big Picture. Praise them when they overcome their self-defeating thoughts by themselves and encourage them to share with you the process of their thinking. Advice them to make a positive thought every time they have a negative one. We cannot rule out the negative thoughts from our head. But we can fight them with positive ones and bring more balance to our life.