A couple of months ago, a San Francisco public defender was assigned a case. The client was a 19-year-old African American arrested for carrying a gun. He faced a stiff sentence for weapon possession.

He explained to his attorney that he began carrying a gun after his best friend was shot dead by rival gang members at war with a gang in his neighborhood. He was not part of that group, but he feared he would be killed in the violence that rocked his streets.

The client’s lawyer, who had grown up in an upper-class neighborhood and graduated from a good school, had a hard time understanding this explanation. Why, she wondered, didn’t her client just call the police?

This lack of understanding put the lawyer and client in a difficult position. A lawyer who doubts her client will struggle to convince a jury. She might also worry that jurors couldn’t possibly empathize, and push him to plead guilty and accept a plea.

* * *

Decades of research has shown that we all possess biases that we are not consciously aware of, which affect our understanding, actions and decisions. Dozens of studies have shown that police officers, judges, prosecutors and defense attorneys suffer from implicit biases, and that it affects the outcomes in criminal cases. It is likely one of the reasons non-white Americans are disproportionately arrested and sentenced. Lawyers may decide to argue a point, such as whether the defendant’s actions were reasonable, based on how they perceive a client.

Given that most public defenders handle a high volume of cases and clients — sometimes in the hundreds — their decision-making process is vulnerable to unconscious bias. A public defender may try harder for a client that he or she perceives as more educated or likely to be successful because of their race.

I didn’t always understand this. I’m the elected public defender of San Francisco, and I was first approached about training my staff on implicit bias four years ago. I was skeptical. My staff works with ethnic minorities every day, I thought. Many had come to this line of work because of concern over racial disparities. How could we be biased against those who we represent?

But I quickly learned that public defenders are not immune from stereotypes and perceptions that influence our decision-making process.

To start, I took Harvard’s Implicit Association test. In it, images of white and black faces flash on the screen as the user uses a keyboard to quickly make certain choices: good, bad, positive or negative. The research shows that humans think and process information by making automatic associations between concepts. The test results showed that I, like most people who have taken the test, suffered from unconscious bias.

I also began reading studies on how defense lawyers were affected by implicit bias. One study showed that defense attorneys in death penalty cases paired pictures of white-skinned faces with stereotypically good words; they paired “bad” words with black faces. The study also found that 88 percent of U.S. attorneys are Caucasian and the vast majority of attorneys have “automatic reactions that make associating white with good easier than associating white with bad.” This made me realize that black clients had an extra obstacle to obtain justice because their lawyers’ biases could affect how hard the lawyer pushed for them.

This is also problematic because of the prevalence of plea bargaining. In most jurisdictions, over 95 percent of the cases that are not dismissed or diverted result in a plea bargain. Past studies have suggested that attorneys may consider race in assessing the client’s chances of conviction and may therefore be willing to recommend higher sentences to account for a biased system.

Two years ago, we partnered with social science researchers from the Quattrone Center for the Fair Administration of Justice Plea to measure racial disparities in our plea bargains, and to determine whether the race of a client — or an attorney — affects outcomes. While the final study has not been released, the preliminary data shows a clear correlation between race and outcomes. Black defendants were more likely to be convicted of more charges and received more severe sentences. Armed with this information, we can now begin comparing outcomes and determining whether there is a rational explanation as to why they are different.

All of this research convinced me that I need to train my staff on how we form biases and how they potentially affect our work. The bias training we now undergo twice-yearly explores the subtle assumptions we make based on race. It forced us to examine who we choose to associate with, and who we choose not to, and how our fears and misperceptions about people affect the way we interact with them and ultimately represent them in court. And it required us to confront our own racism.

We also instituted some practical safeguards: Public defenders are encouraged to seek feedback from colleagues about potential biases and use checklist tools that ask questions such as “how would I handle this case different if my client was another race or had a different social background?” And we combat our own biases by getting to know our clients and their families. It is then they become individuals and not just criminal defendants.

The good news is that the research shows that as people become aware of their unconscious biases, and are reminded of them regularly, they can correct for them.

That was the case with the lawyer whose client was caught with a gun. She discussed and explored her own biases in a trial practice group. She also worked with her client’s family and brother, who was a soldier who had just served a tour in Iraq, which helped humanize his brother.

Thanks to these efforts, my lawyer was better able to defend her client. She won an acquittal in his case.