The only definitive way to know if someone has had sex before is to ask them directly.
According to available research, it is impossible to determine someone's virginity through physical examination or tests. Claims about "virginity tests" are unethical, medically inaccurate, and traumatizing. There are no reliable physical indicators to prove whether someone has had sexual intercourse. Therefore, respectful and open communication is the only way to know someone's sexual history.