Virginia Attorney General Mark R. Herring said Tuesday that courts would probably rule that discrimination on the basis of sexual orientation or gender identity violates state law.

The opinion, which came in response to a request by a conservative lawmaker and not as a reaction to a specific case, follows the increasing recognition by courts and federal agencies that sex discrimination laws protect gay and transgender people, LGBT advocates say.

Herring (D) said several times in his 19-page opinion that it would be “premature” for him to “categorically” say whether sex discrimination includes bias on the basis of sexual orientation and gender identity.

But, he wrote, “the unmistakable trend in federal courts is towards construing anti-discrimination statues to prohibit discrimination against LGBT individuals in many circumstances.”

That uncertainty “amounts to an invitation” to test state law in the courts, said Claire Guthrie Gastañaga, executive director of the American Civil Liberties Union of Virginia. “And it’s an invitation we’d certainly like to accept,” she said, although she did not specify a particular case.

A gender neutral bathroom is seen at a restaurant in Washington. (Mandel Ngan/AFP/Getty Images)

Herring’s opinion comes as the issue of transgender rights is debated around the country. The U.S. Justice Department and North Carolina have filed dueling lawsuits over the state’s “bathroom bill,” which has sparked protests and boycotts.

Last month, the U.S. Court of Appeals for the 4th Circuit in Richmond backed high school junior Gavin Grimm of Gloucester, Va., in deferring to the U.S. Education Department’s position that transgender students should have access to the bathrooms of the gender with which they identify.

Now Herring is weighing in with an opinion that some conservative lawmakers and groups have criticized as an attempt to interpret state law to fit his politics. Herring, who is seeking re-election in 2017, has built a national profile on left-leaning causes, from gay marriage and immigration to environmental policy and gun control.

The opinion stemmed from a request by Del. David A. LaRock (R- Loudoun), who sought definitions for “sexual orientation” and “gender identity” and asked how they relate to Virginia’s various statues prohibiting sex discrimination.

LaRock said the issue is about “original intent.”

“Common sense if nothing else tells me when these laws were passed in Virginia and at the federal level, neither anticipated that sex was meant to encompass sexual orientation and gender identity,” he said.

Everyone deserves protection from discrimination, but the LGBT community is asking for “special preference,” he said.

[The legal fight over N.C.’s transgender bathroom law, in 4 questions]

Earlier this year, LaRock tried unsuccessfully to pass a law overturning a Fairfax School Board policy that includes transgender students and staff members in the school system’s nondiscrimination policy.

The right-leaning Family Foundation of Virginia said the Virginia General Assembly and Congress, both of which are controlled by Republicans, have repeatedly declined to protect sexual orientation “because no evidence of egregious discrimination exists.”

“The Attorney General is basing his opinion on the opinion of the Obama administration, the opinion of his friends at the ACLU, and his political aspirations,” Victoria Cobb, president of the Family Foundation of Virginia, said in a statement. “What the law actually says clearly doesn’t matter to him.”

The debate illustrates the culture wars playing out in Virginia and around the country.

Earlier this year, Gov. Terry McAuliffe (D) vetoed a Republican-backed bill that would have prohibited state agencies from punishing religious organizations that discriminate against same-sex couples.

The gay rights group Equality Virginia, which opposed that bill, said advocates will continue to push for laws that more clearly prohibit LGBT discrimination.

“Although these protections are increasingly clear, based on federal law and judicial decisions, we will also continue to call on the Virginia legislature to make these protections even more explicit under state law,” Executive Director James Parrish said in a statement.

Del. Kenneth R. Plum (D-Fairfax), who also requested Herring’s advice on “sex discrimination” and the law, praised the opinion as a historic first that separates Virginia from North Carolina and Mississippi, which recently passed a law allowing businesses to refuse service to gay people.

“We haven’t reached the period at the end of the sentence yet,” Plum said. “But this puts Virginia on the right side of the definition of human rights.”