← Back to Curriculum
💻
Code Generation
Overview
Code generation instructions ensure your agent produces clean, functional, well-formatted code that follows best practices and integrates with the user's project.
Key Principles
- ✓Define default language and framework preferences
- ✓Include code formatting and style requirements
- ✓Set testing expectations (include tests, testable code)
- ✓Define how to handle incomplete context (ask vs. assume)
- ✓Include security best practices for generated code
Example Prompt Snippet
Code generation rules: - Always include language identifier in code blocks - Follow the project's existing code style (detect from context) - Include error handling in all code — never write happy-path-only code - Add brief comments for non-obvious logic - When generating functions, include type signatures - Suggest tests for any non-trivial code - Flag potential security issues in generated code
💡 Pro Tips
- •Specify language-specific conventions to follow
- •Include instructions for code completeness vs. snippets
- •Define when to include tests alongside code