[ETR #68] This Prompt Prevents Python Mistakes


Extract. Transform. Read.

A newsletter from PipelineToDE

Hi past, present or future data professional!

Despite crushing autocorrect scenarios, most AI code assistants like CoPilot miss a critical step when helping developers of any experience level: Validation. Arguably, leveraging an AI Agent to validate a code’s quality is on the user.

But a surprising amount of experienced programmers are taking the worrying approach of believing an AI’s first “thought” when it comes to code that will ultimately be deployed. I’ve seen this trust betray a peer to the point after they submitted so much AI first thought slop that they were fired.

As a long-time AI hold out, I like to think I use it tactfully and, more importantly, skeptically.

To help me write more polished code, I recently scribbled a prompt to compel my AI Agent to act like an operating system so it could “run” my code before I actually hit run in my IDE.

Feel free to steal it to identify and avoid Python errors.

You're an operating system running Python. I want you to run any files I submit. Print the logs included. If there are any errors, you are to log the error and conduct a stack trace.

Only print errors. Do not print warnings, as you are to assume warnings are disabled. Based on the operations, approximate a runtime. For any files generated, log a full file path. Once you have found any and all errors, act as Pylance and highlight any variables not being referenced in the script.

Conduct this operation for all files submitted. Additionally, print a list of any and all libraries and/or dependencies not being utilized. Make suggestions to combine/consolidate dependencies in the import statements.

Finally, act as the Python library black. Clean up and format the final script according to best practices.

Summarize your feedback on the runs in the style of a senior developer conducting a pull request (PR) rev

Confirm you understand all components of the prompt and ask for clarification before proceeding. Only run the script when I type “run.”

A quick breakdown

  • Persona: I want the agent to impersonate an operating system (OS) running Python so it can process code as a Python compiler would
  • Input: Python files. At work I typically work with multiple files, i.e. a config file for variables or a utility file with helper functions.
  • Constraints: Don’t print warnings. Do not run until given the command “run”; this allows you to prompt the agent like a terminal’s command line interface (CLI). Confirm understanding: I include this so I don’t get overwhelmed with a paragraph of questions and the agent simply replies "Ready for the next file.”

I also included two Python-specific behaviors that I use frequently within an IDE.

  • Pylance: This is Microsoft’s VS Code extension to “provide performant language support.” I’ve most often encountered Pylance when it highlights unused variables/packages
  • black: This is a Python formatting library I use on the “final drafts” before I commit to production repositories. This ensures the final code is formatted according to best practices (pip install black to use locally)

The inclusion of a Senior Developer persona ensures you get an output that mimics a code review and personalizes the interaction as more of a “coding buddy” than a dry code spell check.

The code validation prompt above solves one crucial part of the job: Ensuring code quality. But building a job-winning project is about mastering the entire process: from ideation and execution to nailing the interview presentation.

I detail this full framework, including the validation prompt and other proven techniques for project execution, in my new ebook, which I’ll be releasing to those on the waitlist next week.

Join now for your last chance to gain early access to a comprehensive career resource that will elevate your job candidacy and empower technical development—all for less than 10 USD.

Thanks for ingesting,

-Zach Quinn

Extract. Transform. Read.

Reaching 20k+ readers on Medium and over 3k learners by email, I draw on my 4 years of experience as a Senior Data Engineer to demystify data science, cloud and programming concepts while sharing job hunt strategies so you can land and excel in data-driven roles. Subscribe for 500 words of actionable advice every Thursday.

Read more from Extract. Transform. Read.

Hi fellow data professional! Next time you think you’ve tried everything in your job search, remember: I once worked with a guy who got hired at a national broadcast network on the strength of his parody rap. The intern, Jake, didn’t have a network or elite contacts, but he wanted an internship at The Tonight Show, a competitive role with over 10,000 applicants per semester. So, he recreated a shot-for-shot parody of a song previously performed on the show, rewritten with lyrics specifically...

Hi fellow data professional! For the past month I’ve been working on my most ambitious personal project: Purchasing and renovating a house. The first major upgrade? Replacing 70+-year-old windows. And while there’s probably a tech work comparison to gutting a legacy system to build anew, what I want to focus on is the deal I brokered and how you can use similar leverage in your interviews. Because I got $1200 off a house’s worth of windows as a result of market research, due diligence and a...

Hi fellow data professional! Big news from my home base of Orlando: Disney hired a new CEO with a pay package of nearly $40 million. If you read beyond the headline you’ll see that his base salary is “only” 2.5 million with the possibility of up to a 250% target incentive and some $26-ish million in stock options. This is why you, the job seeker, need to think beyond base salary and look at TC. Total compensation. Thanks to labor transparency laws passed in hiring hubs like New York and...