Advanced Prompt Example for Developers & Aspiring "ChatGPT" Programmers

Advanced Prompt Example for Using LLMs Effectively for Programming

In partnership with

Prompting tips for developers, or those interested in programming

Read Time: 4 mins

Guardians,

We’ve hit the 1,000+ mark! In today’s edition, we will laser-focus on one domain only. Let me explain why:

  • By now, you know about prompt frameworks.

  • You know tools exist for specific tasks that are far better than ChatGPT (due to their workflow/prompt) and we will continue to uncover more of them going forward.

  • BUT, you have not really seen a specialized prompt for a particular use case, yet. Lets change that!

For those who are interested in programming, or do it on a regular basis - this is for you! But, if you’re in a different field - have a look at it anyway. Because I will be explaining what makes the prompt.. special, and you can add those ingredients to yours.

Before we proceed to that, I’d love for you to check out CloudDevs platform - the largest tech talent platform.

LatAm Senior Tech Hiring Made Simple

CloudDevs streamlines the experience of finding and hiring LatAm tech professionals. Their pool is the largest collection of tech talent in LatAm, with over 10,000 senior engineers with a minimum of 7 years of experience ready to join your team.

By hiring through CloudDevs, EasyHealth (just completed a $135M round) has saved 70% on new engineers and hired within 5 days.

Here comes the prompt

I used (a bit more advanced version of) this for writing Python code for a rather complex application that I was creating for myself. But the version I’m sharing below captures the key things I want to share. Here it goes (btw - works much better with prompt chaining but I don’t want to overwhelm you .. yet):

<roles> 

You are an experienced Python developer working on a project that involves writing code for various components. Your role includes not only writing the initial code but also acting as your own manager and senior QA engineer to review and improve the code

</roles>

You always follow the below instructions step-by-step:

<instructions>

<step1> 

I will provide you with a detailed description of the task or component to be programmed. This could be anything from solving a specific bug, implementing an algorithm, or creating a utility function. Understand it fully before moving to next step. Ask questions, if instructions are not clear.

</step1>

<step2>

Write the initial code based on the task description, ensuring that your code adheres to best practices, follows Python conventions, and is well-organized. Handle edge cases and consider performance optimizations where necessary. Display the code.

</step2>

<step3> 

Take a break and then take on the role of a QA Engineer. Write test cases for the function you’ve implemented. Cover different scenarios, including normal inputs, edge cases, and invalid inputs. Ensure that the test cases are comprehensive and cover all relevant aspects of the function.

</step3>

<step4>

Run the code against test cases generated in step3. If the code passes all test cases, proceed to the next step. If any test case fails, debug and fix the issues and rerun against test cases until all test cases pass. Display the code once it passes all test cases.

</step4>

<step5>

At this stage, the code has full test case coverage. Now, take a break and then act as your own manager, review the code. Look for logical errors, potential bugs, and areas for improvement. Consider readability, maintainability, and efficiency. Write actionable feedback and changes to implement for the programmer.

</step5>

<step6>

Rewrite the code to reflect the feedback by your manager. Keep iterating until there is no more feedback. Display the final code.

</step6>

<step7>

Rerun the final program against the test cases QA provided in step3. Ensure they all still pass. If not, iterate between step2 till step7 until this condition is satisfied.

</step7>

</instructions>

Key Takeaways

Below are the key things I’d like for you to notice in the above prompt.

(If you like what you’re reading so far, do share it with others - I’ve added the referral program link at the bottom. Would love your support in reaching the 2000+ mark).

  • Prompting frameworks are great … to start! But you don’t always need to use them. Create your own on the go. Purpose is to provide a coherent structured input and guidance to the LLM about your task.

  • What makes you unique at your role? What considerations do you keep consciously or subconsciously that make your deliverables/work unique? Add that to the instruction set. Example from the prompt: “Consider readability, maintainability, and efficiency.

  • LLMs do have quite a lot of similarities with humans. Offering a tip, a break, etc. have in the past been very effective techniques to push the LLM to do better (not very true of late). Example: “Have a break and then… “. I used it before I asked it to shift characters. Just so it wears a different hat after the break/transition.

  • <XML tags> In the last edition, there were only opening tags, now we see closing tags too. This is because LLMs understand this format really well. Using these provides it a clear indication that a “section” is over. </XML tags>

  • And most importantly, notice the workflow. That is most important. PROVIDE it a step-by-step guide to follow (or you can ask it in a separate convo to suggest you a step-by-step process for xyz task and then copy paste that into your main prompt). You can apply this learning to any type of task. Don’t say “Write an SEO-optimized article”. Provide it the workflow for that. Otherwise, be prepared for an output that maybe looks okay (or great, depends on your quality standards), but it won’t really be achieving that task very well.

I’ve got more I wanted to share today, but I don’t want to make this excessively long. I promised bite-sized tips, and let’s not break that covenant so soon 😄

Before you go:

How many emails do you write on a weekly-basis?

I send roughly:

Login or Subscribe to participate in polls.

P.S: If you have questions or suggestions, just reply to this email, I try to answer and be helpful.

See you in the next one! Ciao.

Reply

or to participate.