A United States federal judge has ruled that the Trump administration's continuing separations of families at the US-Mexico border based on parents' criminal history or health exclusions are being carried out with proper discretion.

The ruling, by US District Judge Dana Sabraw in San Diego, California on Monday, was a rare victory for the government in a case that has been ongoing since 2018.

More:

The American Civil Liberties Union (ACLU) first brought the case over President Donald Trump's "zero-tolerance" policy of criminally prosecuting all border crossers, which led to the separation of hundreds of families and sparked national outrage. Sabraw had ordered the administration to find and reunite separated families.

Trump officially halted the practice with an executive order on June 20, 2018. But the ACLU claimed in court that since then, the government has separated more than 1,000 families in violation of Sabraw's order.

The government has said it separates families when it suspects the parent has a criminal record or a communicable disease - or when there are questions about the relationship between the adult and the migrant child. It claimed its current practice is no different than that of prior administrations.

Immigration activists hold signs objecting to family separation during a rally to protest against the Trump administration's immigration policy, outside the White House in Washington, US, June 30, 2018 [Joshua Roberts/Reuters]

The rights group argued, however, that the administration was taking children from parents when they had only minor infractions such as traffic violations or previous illegal border crossings.

Sabraw found government officials were "generally exercising their discretion to separate families at the border" in a manner consistent with migrants' "rights to family integrity and the Court's orders".

The judge added there was no evidence before the court that the government has "returned to systematically separating families at the border".

Sabraw did say that the government should use its rapid DNA testing technology to confirm parentage and not separate families based on "subjective concerns" alone.

The ACLU highlighted that part of the ruling in a statement: "The court strongly reaffirmed that the Trump administration bears the burden if it attempts to separate families based on an accusation that the adult is not the child's parent," ACLU lawyer Lee Gelernt said.

The group said it was considering its next move in the case.

The US Department of Justice did not immediately respond to a request for comment.