Skip to Content

Enhancing Python API with ChatGPT

Alejandro Tommasino is a fixer. Well, he’s a Solutions Architect at ITX Corp. But when something’s not working properly and no one else can figure out why, you call in Ale.

That’s exactly what happened when ITX was deploying a new API to access a MySQL database. The codebase was supposed to go into multiple databases, create a report of ITX employees and their roles from the data, and then deliver that report. However, the site would always mysteriously crash about six hours after the report was delivered.

The team was stumped; a lack of error management in the code prevented them from figuring out what exactly was failing. If your car just shut down while you were driving without showing something like a check engine light, anything could be the problem.

So, that’s what Ale was tasked with. The problem? Python. Although Ale had experience with C#, PHP, and Java, the project was written in Python, a programming language that he had never even touched before.

Very early on, Ale decided that he would use ChatGPT to help diagnose and solve the problem; however, he realized the AI would be best used not as a magic box that spat out code, but as a learning tool. “It’s cool to say AI fixes everything, but when it comes to technical things, like coding, there are still a lot of errors,” Ale said. “When I moved my mindset to not having the AI do the work for me, but be there for me and enable me, that’s where I found it to be most helpful.”

Ale started by putting little snippets of code into the AI, asking for an explanation of them. As ChatGPT explained the different elements to him, Ale started to understand the structure of the code and what each line of code was actually doing. “I frequently am brought onto projects where I don’t know the project, the language, the architecture; I need to learn everything. I’ve been through this experience without ChatGPT, and this was way less stressful.”

After he got a grasp of what was going on in the codebase, Ale had a hunch: maybe it was something to do with the database connections. Plugging the relevant code into ChatGPT, Ale asked if that was the case. ChatGPT replied that it was customary to run the script on the database and then afterward close the connections to prevent a crash. Ale double-checked the code: no script to close the connections.

His hunch proven and the problem identified, it was a simple matter for Ale to write some new code with his newfound knowledge. Ale became comfortable reading and writing Python because of how he used ChatGPT. The AI wasn’t doing things for him; rather, Ale was using it as a mentor: almost like coding during your professor’s office hours, able to look up at any time and get clarification or advice.

Ale implemented his fix and created a robust error management system to prevent future confusion. The project reminded Ale of something he once heard from one of his own professors: “You either prevent it from failing or make it fail gracefully.” In coding, that can be the difference between a helpful error message and the dreaded blue screen of death.

When asked about why he didn’t just use ChatGPT to solve the problem for him, Ale was quick to answer: he wanted to learn Python. “I didn’t go into this asking, ‘hey, write this code for me’ because I knew there was a huge chance that there were going to be mistakes in the code that it gave me,” Ale said, “I didn’t have the tools to understand, if ChatGPT got it wrong, how to fix it.”

According to Ale, the codebase ended up much healthier; the code was of a higher quality and far more secure. In addition, it could now handle even more connections to the databases than ever before.

ChatGPT doesn’t just have to be a magic box that solutions come out of. Ale’s genuine interest in his work led him to use AI in a way that not only sped up his work on this project but left him with lasting skills that he will be sure to use again the next time ITX needs something fixed.


Andrew Tyrell-Smith is a UX Writer at ITX. He graduated from the University of San Diego with a BA in English, and has spoken every word he has ever written out loud.

Like what you see? Let’s talk now.

Reach Out