Prompt Engineering for Developers
Getting good code out of an LLM is a skill. Here are three techniques to improve your results immediately.
1. Chain of Thought (CoT)
Don't just ask for the code. Ask the model to "think step by step" or "explain the logic first".
Bad: "Write a function to parse CSV."
Good: "Outline the steps to parse a CSV file robustly, handling edge cases like unclosed quotes. Then, implement the function in Python."
2. Provide Examples (Few-Shot)
Give the model 1 or 2 examples of the style you want.
"Here is how we handle error logging in this repo: [Example]. Now write a function that..."
3. Specify the Interface
Define the input and output types clearly. TypeScript interfaces are actually great prompts even for non-TS languages because they are precise contracts.