Programming with a Purpose:

Development in the Realm of Social and Legal Issues

Sean Byrne
5 min readFeb 5, 2021

People often ask, “what can you do with programming skills other than coding silly videogames and such?” Well, let me elaborate on that question by describing the most recent project to which I lent my brain. The company for whom we worked is a nonprofit called Human Rights First that provides legal support for immigrants seeking asylum. They work across the nation and have roughly 63 full time staff along with several attorneys working pro bono for their immigrant clients. The people at this nonprofit strive to help the less fortunate that are trying to escape the dangers of their home countries.

General outline of the application

One struggle that these attorneys have when providing help to their clients is difficulty preparing for case trials. For example, an attorney might be representing a client from Guatemala and in preparation for the court hearing the attorney might find it useful to know how often the presiding judge grants asylum to immigrants from Guatemala. To solve this problem, the team was tasked to create an app that incorporates ML models to make predictions on the outcome of a case hearing based on various parameters such as presiding judge, country of origin, social group, political affiliation and various other parameters.

Databases: Boring but Important

One concern was sourcing data to build up the database. Finding case hearing documents has been tricky.

Database prototyping with dummy data as seen in pgAdmin

However, that doesn’t mean it has held up the progress. While waiting to build up a stash of documents with which to populate the database, work was done to build out the database so that it would be ready to accommodate the incoming documents. So, how could I build out a database without having data to reference? Well, we had a good understanding of how the user would be using the app and so we constructed the database based on that. For example, since a user will be able to update the database with their own case hearing documents, one table in the database is constructed to hold data for each case and it’s relevant info.

Viewing the DB table on pgAdmin for the SQL enthusiasts

Another table will be constructed around each judge since it’s important for the user to know which way a judge will decide regarding different aspects of a case, such as country of origin or if the client belongs to a specific social group.

Now, bear with me on these next few lines because I’m really going to get into the weeds with some database jargon. In building out the database I had to keep the future in mind. To accommodate that need I used the Pydantic and SQLAlchemy packages because they “play nicely” with the FastAPI framework and because they make database construction, connection, and querying easy to do. Let me elaborate on that.

Creating a DB table with SQLAlchemy

To create a database table, SQLAlchemy has some class objects such as Table(), MetaData(), and Column() that can be instantiated. Then to create the table simply use them together in the manner illustrated in the image above.

Inheriting from pydantic’s BaseModel class to create the class model of the data

Now comes pydantic. This package has some modules as well which can be used to make some fine and beautiful models. You might have noticed that I’m redundantly specifying data types in the construction of the DB table and the class model. That’s for the sake of data validation so that the user will be sure to input the relevant data and to maintain the integrity of the DB.

More to Come

At the time of writing, this application has a connected database to persist data and the ability to scrape data from scanned court documents.

A rendering of the DB routes on my local browser and the terminal showing the successful connections

Furthermore, it can roughly analyze that scraped data to return some insights, such as a percentage breakdown of the rulings for each judge in the database. These features are just the tip of the iceberg though, because future iterations will sharpen up the analysis algorithm to provide more insight. Also, more work will be done to incorporate a tagging system to allow the user to classify each case with more parameters which will in turn allow for more analysis to provide more robust insight.

I’m very excited for the future of this application. However, one of the limiting factors pertains to the data. In developing this application my team members and I had to work around a not so big corpus of court documents. It was enough to get started and create the architecture for a database but analysis was somewhat limited. Therefore our stakeholders and future developers have a good starting point regarding the application scaffolding but they will need to source more documents to add to the database in order to get more robust analysis and insight.

I feel very grateful to have had the opportunity to contribute to this project. The work my team members and I did will provide hope and opportunity to asylees seeking safety from the perils of their home countries. I know several people dealing with immigration issues and so I’ve seen the pain and struggle they face in not feeling safe in the place they call home. For me this work was very rewarding on many levels because I was able to further my skills as a developer, especially regarding database construction and connection, and the product of the work will be used to help those seeking a better opportunity in life.

Check out the repo for the data science backend

--

--