A mistake by a Manchester firm which specialises in drug testing led to a mother-of-two at the centre of local authority care proceedings wrongly being accused of taking cocaine, a High Court judge heard.
Lawyers said the woman's drug use and its impact on her ability to care for her children was a "major issue" in the proceedings, Mr Justice Baker was told.
The judge said tests on strands of the woman's hair were therefore conducted.
Specialists at Trimega Laboratories carried out tests in June last year and the results "purported" to show that the woman had been "using increasing amounts of cocaine and opiates right up to the date of the sample being taken", the judge heard.
But the woman, whose children are aged four and three, "vehemently denied" the allegation - and a second test by another firm showed she had been "abstinent" for several months.
Trimega conceded that its analysis had been "erroneous and unreliable", said the judge. He said the "precise error" remained unclear.
Bosses told Mr Justice Baker that the woman should have been given an apology for the failure to provide an "accurate and reliable service".
They said the firm had carried out a wide-ranging review and instituted "a large number of changes".
Mr Justice Baker said the woman remained abstinent and there was "cautious optimism" that she would be able to care for her children.
Detail of the case emerged in a written judgment released by Mr Justice Baker following hearings in the Family Division of the High Court in London.
The judge said care proceedings had been brought by Bristol City Council in respect of the woman's children. He did not identify the woman or the children.
Trimega's website says it offers services including hair testing for drugs, alcohol and steroids, as well as blood alcohol testing and adoption testing.
A spokesman for the firm apologised for a "human error". He said a nurse at an "external collection agency" incorrectly labelled a sample.