Prompt Engineering
Essential techniques for Software Engineers
Prompt Engineering for Software Engineers
Prompt Engineering isn't about "tricking" the AI. It's about clear, unambiguous communication of intent.
The 6 Essential Techniques
1. Zero-shot vs Few-shot (The "Example" Rule)
Zero-shot: Asking without examples. The model guesses the format you want. Bad: "Write a validation function for email."
Few-shot: Providing examples of input -> output.
Good:
"Create a validation function. Follow this pattern:
Input: validateName('John') -> Output: { valid: true, error: null }
Now write: validateEmail(email)"
Why it works: Examples constrain the infinite possibilities of the model's output to the specific format you need.
2. Chain-of-Thought (CoT)
Ask the model to reason before it answers. This drastically reduces logic errors.
Prompt: "Analyze this React Native navigation error. Think step-by-step:
- Check imports.
- Verify nesting of Navigators.
- Check screen registration. Then provide the fix."
Why it works: LLMs are auto-regressive. Forcing them to output reasoning tokens before the answer gives them "space to think" and increases accuracy.
3. Decomposition (Break it Down)
Large tasks overwhelm models, leading to "lazy" code or hallucinations.
Bad: "Build the entire Settings feature." Good (Iterative):
- "Create the Settings screen UI layout."
- "Create the Profile update form."
- "Connect the form to Supabase update function."
4. ReAct (Reasoning + Action)
Explicitly separate the thought process from the code generation.
Prompt: "You are an expert.
Thought: I need to fetch user data.
Action: Check if useAuth hook exists.
Thought: It does. I will use it.
Code: const { user } = useAuth();"
5. Self-Critique
Reviewing code after generation is often more effective than trying to get it perfect in one go.
Prompt: "Generate the component. Then, acting as a Security Auditor, review the code for XSS vulnerabilities and bold them. Finally, provide the secure version."
6. Role Playing (System Instructions)
Assigning a persona focuses the model's training data retrieval.
Prompt: "Act as a Senior React Native Engineer who implies Clean Architecture and SOLID principles. Review this code."
The "Context" Factor
Prompt engineering is only 50% of the equation. The other 50% is Context Engineering (what files you feed the model).
[!TIP] Always check your
.agent/context_map.mdto see what the agent "knows" about your project structure.