[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 nearly 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.

Extract. Transform. Read. A newsletter from PipelineToDE Hi past, present or future data professional! After choosing a dataset, one of the most significant decisions you must make when creating displayable work is: How am I going to build this thing? For some, you may try to “vibe code” along with an LLM doing the grunt technical work. If you choose this approach, be warned: Nearly half of all “vibe code” generated contains security vulnerabilities and that’s before you even consider its...

Extract. Transform. Read. A newsletter from PipelineToDE Amid layoff announcements from Meta, Amazon and even UPS, it's job aggregator Indeed that signals a different concern for entry-level data job seekers. This week a post on Blind revealed Indeed’s plan to quietly reduce junior roles. They’re not necessarily going to stop hiring or layoff juniors (though they are losing 1300 employees by end of year)—they’re just going to stop paying attention to them. Specifically, Indeed will no longer...

Extract. Transform. Read. A newsletter from PipelineToDE Hi past, present or future data professional! I want to share the single most important realization I had back in the summer of 2021. I was burned out, juggling two part-time jobs, trying to plan a wedding, and drowning in full-time job applications. I felt overwhelmed and underprepared as I plunged into a sea of candidates I perceived to be more intelligent and better "fits" than me. My portfolio was full of the usual Titanic, Iris,...