4. Prompt Engineering
4.1 What is a prompt?
A prompt is an instruction or input provided to an AI system.
Weak:
Fix this.
Better:
Investigate the failing login test.
Do not edit files yet.
Identify:
1. The failing test
2. The root cause
3. The relevant files
4. A proposed fix
5. How the fix should be verified
4.2 A useful prompt structure
Role / context
Goal
Scope
Constraints
Inputs
Expected output
Verification
Example:
Context:
This is a FastAPI application.
Goal:
Fix the failing authentication test.
Scope:
Only modify authentication-related code.
Constraints:
Do not change the database schema.
Verification:
Run the authentication test suite.
Output:
Explain the root cause and summarize the changes.
4.3 Planning prompts
For large tasks, ask the agent to analyze before modifying.
Analyze the repository and create an implementation plan.
Do not modify files.
Include:
- Current architecture
- Files that will change
- New files
- Risks
- Tests
- Rollback considerations
4.4 Implementation prompts
After approving a plan:
Implement the approved plan.
Follow AGENTS.md.
Keep the change scoped.
Run relevant tests.
Do not make unrelated refactors.
4.5 Review prompts
Review the current changes.
Do not modify files.
Check:
- Correctness
- Security
- Error handling
- Performance
- Tests
- Maintainability
Report findings with file and line references where possible.
4.6 Prompt anti-patterns
Avoid:
- Huge unrelated context
- Contradictory instructions
- Vague goals
- Missing verification
- Asking for irreversible actions without approval
Exercise
Write prompts for:
- Code exploration
- Architecture planning
- Implementation
- Testing
- Security review