D.C. Mayor Muriel E. Bowser (D) (Jabin Botsford/The Washington Post)

D.C. MAYOR Muriel E. Bowser (D), eager to show that she is prepared to stand up to the Trump administration, recently announced plans to award grant funding to advocates and defense lawyers who would represent the city’s estimated 25,000 undocumented immigrants in legal proceedings, including those faced with deportation. Protecting a vulnerable community that faces an array of legal travails is an admirable goal, and immigrants with lawyers fare better in legal proceedings than those without.

In drafting the program’s fine print, however, D.C. officials should take care: It’s not just most undocumented immigrants facing legal travails who merit protections. So do ordinary Washingtonians.

Officials in Ms. Bowser’s office insist, with reason, that the District’s undocumented immigrants are generally law-abiding. Unlike other localities, where most long-term prisoners would be incarcerated in the state’s prison system, those convicted of serious crimes in the District are sent to federal prisons. In the case of illegal immigrants, that means there is little or no chance they will be released back into the District upon completion of their sentence; they are far more likely to be deported.

Nonetheless, it is worth bearing in mind the unhappy experience of some other so-called sanctuary cities, whose zeal to defy federal immigration authorities has at times defeated common sense. In the prime example, San Francisco officials in 2015 ignored a detainer, an official request from federal immigration officials seeking custody of an undocumented immigrant with a long record of drug offenses. The man should have been turned over to federal officials; instead, he was released. A few weeks later, he shot and killed a young woman strolling with her father on the waterfront.

To its credit, the District gives federal officials a 48-hour heads up before the scheduled release from the D.C. Jail of any undocumented immigrant for whom Immigration and Customs Enforcement has issued a detainer. Officials say they recognize a legitimate middle ground between complete noncooperation and allowing local police to become an auxiliary deportation force. In the District’s case, that means police do not ask the immigration status of those it detains or arrests, although defendants are fingerprinted when charged with crimes, and those fingerprints are available to federal law enforcement agencies, including ICE.

That’s a sensible stance, but it could be more sensible. Even if only a small percentage of the city’s undocumented immigrants have serious or violent criminal records, perhaps from other states, that still constitutes hundreds of people who would be logical candidates for deportation. They should be exempted from whatever assistance the city’s grant program might provide, once it is up and running later this year.

Other cities, including New York, have taken steps to protect some ex-convict undocumented immigrants from deportation but not others, depending on the severity of their crimes. That’s a sound policy, and D.C. officials should take note.