In the US, an F1 STEM student can have an OPT after graduation and work without a work visa for up to 3 years. But the work has to be related to the major of F1. How to determine if the work is counted as being related to the F1 major?
Many cases are quite clear cut - someone graduating with a physics PhD getting a physics postdoc is obviously fine, for example. Generally, I think the answer is to be reasonable. If you (who's the person most familiar with the details about both your degree and job) struggle to come up with a reasonable explanation as to how the job is related to the degree, using skills developed during the degree, and at the right level, well, it probably wouldn't count. Note that you need to provide that motivation when listing the employer in the SEVP portal. If you're uncertain, or if this is a less clear cut case, do discuss it with the International Office at your university. They'll have a good idea about where the line tends to be drawn.
It's also useful to have a letter from your employer or academic advisor outlining how your job duties relate to the degree. Unlike the brief motivation for the SEVP portal, this letter is for later - either future visa applications (e.g. for the STEM OPT extension) or for being readmitted to the US after travel abroad.
Finally, note that I used the postdoc example since we're on Academia. For nonacademic jobs, and further OPT questions, you might get better answers at Expatriates Stack Exchange.