SAN ANTONIO (AP) — A Texas agency will inspect two of the nation's largest immigrant family detention centers to determine whether to issue them residential child care licenses as part of an effort to keep the facilities open amid a legal challenge.

A judge in August ruled immigrant children could no longer be held in the centers because they aren't licensed to house or care for children. The state, which had previously deemed the federal centers outside its authority, subsequently created a new licensing category to accommodate them.

If the licenses are denied, the federal government could run afoul of U.S. District Judge Dolly Gee's Oct. 23 deadline to comply with her ruling and face renewed questions about the future of family detention.

The South Texas centers opened last year in response to the arrival of tens of thousands of mothers and children from Central America. The policy of detaining children has faced criticism from immigrant advocates from the start. They cite reports of inadequate medical care and other issues as reasons the Texas Department of Family and Protective Services should not issue child care licenses to the facilities.

Patrick Crimmins, spokesman for the state agency, said inspections will likely take place this month. If standards are met, the state would grant six-month provisional licenses.

"The licensing process is rigorous," he said.

But immigrant advocates say it's not rigorous enough.

The state adopted an emergency rule change last month allowing the facilities to become "family residential centers," a new category. Advocates say the move will allow the centers to operate with significant exemptions to usual standards, including allowing more than four people to a room, allowing adults to share bedrooms with children, and allowing boys and girls to be housed together.

"In order to license the family detention facilities you have to lower the minimum standards," said Cristina Parker, immigration coordinator for Austin-based Grassroots Leadership. "These are facilities that don't foster child welfare in the first place."

A letter signed by advocacy groups, lawyers and professors was sent this week to the state agency and Republican Gov. Greg Abbott asking that licenses not be granted. Grassroots Leadership has also filed a lawsuit against Family and Protective Services, alleging it circumvented the normal rule-change processes by not allowing for a public comment period.

A spokeswoman for the Texas attorney general's office, which represents the agency in the lawsuit, said it does not comment on pending litigation.

The detention centers are overseen by U.S. Immigration and Customs Enforcement and run by private prison companies, which are applying for the licenses. According to an application filed by Corrections Corporation of America, the 2,000-bed facility in Dilley would provide child care services that can include handling children at risk to themselves or others and restraining children physically. The application filed by The GEO Group, the contractor at the 500-bed facility in Karnes City, asked only for child care services.

ICE did not answer questions about the licensing, deferring to a statement by Homeland Security Secretary Jeh Johnson last month that said the federal agency is taking steps to comply with the judge's order. Johnson also said family detention "is becoming short term" and that the agency would "make additional improvements when appropriate."

Immigrant rights attorneys describe care given to the detained children as hopelessly inadequate, according to court filings in recent months.

Complaints about the Karnes facility include medical mismanagement and reports of mothers and children being held in medical isolation as punishment.

Pablo Paez, a spokesman for The GEO Group, said the Karnes facility provides high quality care and called allegations to the contrary "unfounded and unsubstantiated."

Filings about the Dilley facility mention untreated or unrecognized ailments that resulted in children being hospitalized, lack of medicines, erroneous vaccine dosages and long waits. Corrections Corporation of America would not comment on the allegations or the licensing process, deferring to the Homeland Security statement.

Crimmins said its inspections will involve pulling a random sample of children's files and determining whether minimum medical and dental standards are being met.

"Up until now we haven't had the regulatory jurisdiction to investigate any allegations," he said. "Now we do."