I agree with all who have said to regress, re-asses, and refer to a doctor or PT. It’s usually the victim that cries out, not the criminal, so although the pain is in the hamstring, it could be coming from a dysfunction above or below.
Once client is cleared for exercise, one thing that I’ve done with clients that has helped has been to shorten and protect their range of motion. For example, I have a client who has knee pain that limits her lunge ability. So, we squat, unloaded, and I place a bench behind her so that she can eccentrically lengthen her glutes and hams on the way down, and the bench stops her from going farther than her knee can handle without pain or misalignment. We work the “down” for one set. We work the “up” for one set. For now, that’s all her knees can take, and it’s enough of a challenge for her leg muscles that we can benefit the legs without risking the knees.