A former school teacher, now pregnant with her first child, will give birth in custody after pleading guilty to having sex with a student while she taught at Sydney Grammar School.

The 34-year-old pleaded guilty to five counts of sexual intercourse with the 17-year-old boy, with the offences taking place in a range of locations including classrooms.

The woman, who is pregnant with her first child to her husband, has been sentenced to 15 months' prison, with a non-parole period of seven months.

Judge Paul Lakatos described the victim and the offender as "lost souls" who initially came together with good intentions before a line was crossed.

He said it was "regrettable" the woman's child would be born in custody, but due to the serious nature of the charges he saw no alternative to a custodial sentence.

Judge Lakatos told the court the conditions she would be subjected to in custody would be "onerous".

The court heard the victim felt "dominated", subjected to "emotional blackmail", harassed, stalked and unsuccessfully attempted to end the relationship multiple times.

The victim also composed a suicide note.

The judge told the District Court the victim suffered major depression, plummeting self-esteem, and suicidal thoughts following the offences and subsequent media coverage of the case.

Judge Lakatos accepted that the teacher was "honest and sincere" in her remorse and said her risk of reoffending was low.

However, he took into account the fact she was warned of becoming too close to her students on three occasions, and that the victim ended the relationship.

The teacher engaged the student in sexual behaviour at least five times over a course of three months in 2016 and offences included intercourse and oral sex.

These occurred not only in classrooms but also in a school storeroom and the teacher's home.

Teacher told student she had marital problems

The court heard the relationship between the pair began innocently, but text messages exchanged between the two in 2015 soon became intimate.

The former teacher disclosed marital problems to the student and told him she believed she was unable to have children.

She also asked him to write sexual fantasy stories.

The victim disclosed to the court he believed the woman would self-harm if he tried to end the relationship and began having panic attacks.

Judge Lakatos considered the mental health of the teacher at the time the affair commenced after three miscarriages and difficulties in her marriage led to symptoms of major depression.

He also noted she had no prior convictions.

The victim was not present in court, but supporters of both parties were emotional as the judge delivered his sentencing remarks for more than an hour.

She will eligible for parole on September 1, 2018.