To prevent the garlic from burning while stir-frying, ensure that you add it into the pan at the same time as the string beans. This helps in lowering the oil temperature, thus reducing the risk of burning the garlic slices.