
523 S.E.2d 106 (1999)
240 Ga. App. 481
GOULD
v.
GOULD.
No. A99A1609.
Court of Appeals of Georgia.
October 6, 1999.
Reconsideration Denied October 21, 1999.
Certiorari Denied February 11, 2000.
*107 George M. Hubbard III, Savannah, for appellant.
Duffy, Feemster & Lewis, Dwight T. Feemster, Savannah, for appellee.
BLACKBURN, Presiding Judge.
Sheri Gould appeals by application the trial court's dismissal, without prejudice, of her petition for modification of a divorce decree and contempt due to her failure to abide by an agreement to mediate. Because we find the divorce decree required Sheri Gould and Keith Gould to submit disputes concerning their minor children to a mediator or family counselor before litigating, we affirm.
The Goulds were divorced in Florida in March 1995. The final judgment of divorce incorporated the Goulds' marital separation agreement. That separation agreement expressed the Goulds' intent to share decision-making responsibility with regard to the care and upbringing of their children. Keith Gould was given residential custody of the children, and Sheri Gould was to have "extensive contact" and "open and liberal visitation" with the children. However, the agreement provided no specific schedule of visitation.
In addition, the agreement provided:
In the event of a disagreement between us on matters of policy affecting the health, education, or welfare of our minor children, we agree to confer with a harmonious attitude best calculated to promote our children's welfare. If, in spite of this conference, we remain in conflict regarding our decisions affecting our minor children, we agree to submit the conflicts to a mediator, counselor or professional person skilled in the area of resolution of family problems. This procedure will be followed *108 to its conclusion prior to either of us seeking relief from the court.
Keith Gould moved with the children to Savannah, Georgia. Moving or a change of geographic location by Keith Gould was contemplated by the separation agreement and was not an issue at the trial court. Subsequently, the Goulds could not agree as to Sheri Gould's visitation with the children. Without seeking resolution of the dispute by a mediator or family counselor, Sheri Gould filed a modification petition in August 1995, which Keith Gould answered. The trial court domesticated the judgment and entered a temporary visitation order. In 1997, Sheri Gould filed an amended modification petition which sought custody of the children.
While the modification action was still pending, Keith Gould filed a motion for contempt in May 1998 regarding telephone contact with the children during Sheri Gould's visitation periods. Sheri Gould raised as a defense Keith Gould's failure to seek mediation of the dispute in accordance with the separation agreement. In June 1998, the trial court dismissed Keith Gould's contempt motion because of his failure to comply with the mediation provision in the agreement before filing suit. In its order, the trial court found that "this provision precludes either party from commencing an action in court prior to `submitting the conflicts to a mediator, counselor, or professional person skilled in the area of resolution of family problems.'"
Thereafter, in August 1998, Keith Gould filed a motion to dismiss or for summary judgment, raising for the first time the defense of failure to state a claim based upon Sheri Gould's failure to submit the custody dispute to a mediator or family counselor. Keith Gould also filed an amended answer which raised the failure to state a claim and the failure to comply with the agreement. The trial court found the mediation provision applied to Sheri Gould's claim, as it had applied to Keith Gould's motion for contempt, and dismissed Sheri Gould's petition for failure to submit the custody dispute to a mediator or family counselor prior to filing suit.
1. Sheri Gould contends the trial court erred by dismissing her petition, arguing that the mediation provision is an affirmative defense which Keith Gould waived by failing to plead it in his first responsive answer. We disagree.
It is undisputed that the mediation provision at issue is a condition precedent to the parties' right to sue. See Sasser & Co. v. Griffin, 133 Ga.App. 83, 89-91(3)(e), 210 S.E.2d 34 (1974). Since Sheri Gould failed to comply with the mediation provision before filing her petition, her petition was subject to a motion to dismiss for failure to state a claim. OCGA § 9-11-12. Although Keith Gould failed to raise this defense in his initial answer, the defense was not waived.
Unlike the defenses identified in OCGA § 9-11-12(b)(2)-(5), which are waived unless they are raised in an initial motion or responsive pleading, the defense of failure to state a claim does not have to be raised in the initial responsive pleading. OCGA § 9-11-12(h)(1), (2); Hayes v. Superior Leasing Corp., 136 Ga.App. 98, 99, 220 S.E.2d 86 (1975) (the defense of failure to state a claim is "unwaiverable, whether or not [it was] raised by motion or by answer"); Carpenters Local Union No.1977 v. Gen. Ins. Co. of America, 167 Ga.App. 299, 306 S.E.2d 383 (1983) (the failure to state a claim upon which relief can be granted may be made in an answer, by motion for judgment on the pleadings or at trial on the merits). See Charles A. Wright & Arthur R. Miller, Fed. Prac. & Proc., Civil 2d § 1392, which is identical to OCGA § 9-11-12(h)(2) (if the defense of failure to state a claim is not raised in a pleading, it can be the subject of a motion for judgment on the pleadings or a motion to dismiss at trial).
Rather, the defense of failure to state a claim "may be made in any pleading permitted or ordered under subsection (a) of Code Section 9-11-7, or by motion for judgment on the pleadings, or at the trial on the merits." OCGA § 9-11-12(h)(2). Under the Civil Practice Act (CPA) the failure to state a claim is a fundamental defense preserved from waiver through trial. OCGA § 9-11-12(h)(2); Capital Assoc. v. Keoho, 173 Ga. App. 627, 628, 327 S.E.2d 586 (1985) ("a defense of failure to state a claim will be waived if no assertion of that defense is made *109 before judgment"); Carpenters Local Union No.1977, supra at 300, 306 S.E.2d 383 (OCGA § 9-11-12(h)(2) allows the defense to be asserted at a trial on the merits); Adams v. Wright, 162 Ga.App. 550, 551(1), 293 S.E.2d 446 (1982) (the defense of failure to state a claim must be asserted before judgment or it is waived).
Keith Gould raised the defense of failure to state a claim in an amendment to his answer[1] and in a motion to dismiss, or in the alternative, motion for summary judgment, asserting Sheri Gould's failure to comply with the mediation provision. Since the defense was raised prior to judgment, it was not waived.
Sheri Gould argues the dismissal was a too drastic sanction exercised under OCGA § 9-11-37. However, OCGA § 9-11-37, which addresses sanctions for discovery abuse, is inapposite. To the contrary, where the complaint fails to state a claim, dismissal is the only remedy. In Sheri Gould's motion to dismiss Keith Gould's motion for contempt, she successfully relied on the same mediation provision.
2. Sheri Gould now contends that the mediation provision under which she sought relief is unenforceable when applied against her. She argues that the court abrogates its duty and obligation to seek the best interests of the minor children by requiring the Goulds to submit the dispute to a mediator or family counselor. To the contrary, mediation or family counseling is an appropriate forum well suited, perhaps better suited than the court system, to resolving disputes concerning the minor children of divorce. Parents are encouraged "to present to the court an agreement respecting any and all issues concerning custody of the minor child." OCGA § 19-9-5. Merely requiring parents to attempt resolution of a custody dispute before litigating does not equate to the court abandoning its obligations to the children. Even if the parents agree on custody issues, the court must still consider the best interests of the child.
The court shall ratify the agreement and make such agreement a part of the court's final judgment in the proceedings unless the court makes specific written factual findings as a part of the final judgment that under the circumstances of the parents and the child in such agreement that the agreement would not be in the best interests of the child.
OCGA § 19-9-5; See Wrightson v. Wrightson, 266 Ga. 493, 467 S.E.2d 578 (1996) (while the court may consider the opinion of a third party, it cannot delegate decisions regarding visitation or custody to the third party). The trial court properly enforced the provisions of the separation agreement.
Judgment affirmed.
BARNES and ELLINGTON, JJ., concur.
NOTES
[1]  "A party may amend his pleading as a matter of course and without leave of court at any time before the entry of a pretrial order." OCGA § 9-11-15(a).
